| org.quickserver.net.server.ClientEventHandler
All known Subclasses: test.org.quickserver.net.server.TestEventHandler, org.quickserver.net.server.impl.DefaultClientEventHandler, filesrv.CommandHandler, echoserver.EchoCommandHandler, org.quickserver.net.qsadmin.CommandHandler, xmladder.CommandHandler, pipeserver.CommandHandler, chatserver.ChatCommandHandler,
ClientEventHandler | public interface ClientEventHandler (Code) | | This interface defines the methods that should be implemented by any
class that wants to handle client events.
Recommendations to be followed when implementing ClientEventHandler
- Should have a default constructor.
- Should be thread safe.
- It should not store any data that may is associated with a particular client.
- If any client data is need to be saved from the client session,
it should be saved to a
ClientData class, which can be retrieved
using handler.getClientData() method.
If not ClientEventHandler is set for QuickServer then a
default implementation
org.quickserver.net.server.impl.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());
}
}
since: 1.4.5 author: Akshathkumar Shetty |
closingConnection | public void closingConnection(ClientHandler handler) throws IOException(Code) | | Method called when client connection is closed.
Don't write to the connection in this method.
Its just information, you can use to log time and ip of client closing connection.
exception: java.io.IOException - if io error in socket |
lostConnection | public void lostConnection(ClientHandler handler) throws IOException(Code) | | Method called when client connection is lost.
Don't write to the connection in this method.
Its just information, to be used at the Server end.
It can be caused due to network errors.
exception: java.io.IOException - if io error in socket |
|
|