public interface ClientEventHandler
Recommendations to be followed when implementing ClientEventHandler
ClientData
class, which can be retrieved
using handler.getClientData() method.
If not ClientEventHandler is set for QuickServer then a
default implementation DefaultClientEventHandler
is used.
Ex:
package echoserver;
import java.net.*;
import java.io.*;
import org.quickserver.net.server.ClientEventHandler;
import org.quickserver.net.server.ClientHandler;
public class EchoEventHandler implements ClientEventHandler {
public void gotConnected(ClientHandler handler)
throws SocketTimeoutException, IOException {
handler.sendSystemMsg("Connection opened : "+
handler.getSocket().getInetAddress());
handler.sendClientMsg("Welcome to EchoServer v1.0 ");
handler.sendClientMsg("Note: Password = Username");
handler.sendClientMsg("Send 'Quit' to exit");
}
public void lostConnection(ClientHandler handler)
throws IOException {
handler.sendSystemMsg("Connection lost : " +
handler.getSocket().getInetAddress());
}
public void closingConnection(ClientHandler handler)
throws IOException {
handler.sendSystemMsg("Connection closing : " +
handler.getSocket().getInetAddress());
}
}
Modifier and Type | Method and Description |
---|---|
void |
closingConnection(ClientHandler handler)
Method called when client connection is closed.
|
void |
gotConnected(ClientHandler handler)
Method called when there is a new client connects
to the QuickServer.
|
void |
lostConnection(ClientHandler handler)
Method called when client connection is lost.
|
void gotConnected(ClientHandler handler) throws java.net.SocketTimeoutException, java.io.IOException
java.net.SocketTimeoutException
- if socket times outjava.io.IOException
- if io error in socketvoid lostConnection(ClientHandler handler) throws java.io.IOException
java.io.IOException
- if io error in socketvoid closingConnection(ClientHandler handler) throws java.io.IOException
java.io.IOException
- if io error in socketCopyright © 2003-2014 QuickServer.org