|
QuickServer v1.4.5 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
This interface defines the methods that should be implemented by any class that wants to handle client interaction.
Recommendations to be followed when implementing ClientCommandHandler
ClientData
class, which can be retrieved
using handler.getClientData() method.
Ex:
package echoserver;
import java.net.*;
import java.io.*;
import org.quickserver.net.server.ClientCommandHandler;
import org.quickserver.net.server.ClientHandler;
public class EchoCommandHandler implements ClientCommandHandler {
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());
}
public void handleCommand(ClientHandler handler, String command)
throws SocketTimeoutException, IOException {
if(command.toLowerCase().equals("quit")) {
handler.sendClientMsg("Bye ;-)");
handler.closeConnection();
} else {
handler.sendClientMsg("Echo : " + command);
}
}
}
Method Summary | |
void |
handleCommand(ClientHandler handler,
java.lang.String command)
Method called every time client sends a line of data. |
Methods inherited from interface org.quickserver.net.server.ClientEventHandler |
closingConnection, gotConnected, lostConnection |
Method Detail |
public void handleCommand(ClientHandler handler, java.lang.String command) throws java.net.SocketTimeoutException, java.io.IOException
java.net.SocketTimeoutException
- if socket times out
java.io.IOException
- if io error in socket
|
QuickServer v1.4.5 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |