1 14 15 package echoserver; 16 17 import java.net.*; 18 import java.io.*; 19 import org.quickserver.net.server.ClientCommandHandler; 20 import org.quickserver.net.server.ClientHandler; 21 import org.quickserver.net.server.ClientEventHandler; 22 import java.util.logging.*; 23 24 public class EchoCommandHandler implements ClientCommandHandler, ClientEventHandler { 25 private static Logger logger = 26 Logger.getLogger(EchoCommandHandler.class.getName()); 27 28 public void gotConnected(ClientHandler handler) 30 throws SocketTimeoutException, IOException { 31 logger.fine("Connection opened : "+handler.getHostAddress()); 32 33 handler.sendClientMsg("+++++++++++++++++++++++++++++++"); 34 handler.sendClientMsg("| Welcome to EchoServer v " + EchoServer.version+" |"); 35 handler.sendClientMsg("| Note: Password = Username |"); 36 handler.sendClientMsg("| Send 'Quit' to exit |"); 37 handler.sendClientMsg("+++++++++++++++++++++++++++++++"); 38 } 39 40 public void lostConnection(ClientHandler handler) 41 throws IOException { 42 handler.sendSystemMsg("Connection lost : "+ 43 handler.getSocket().getInetAddress(), Level.FINE); 44 } 45 public void closingConnection(ClientHandler handler) 46 throws IOException { 47 logger.fine("Connection closed : "+ 48 handler.getSocket().getInetAddress()); 49 } 50 52 public void handleCommand(ClientHandler handler, String command) 53 throws SocketTimeoutException, IOException { 54 if(command.toLowerCase().equals("quit")) { 55 handler.sendClientMsg("Bye ;-)"); 56 handler.closeConnection(); 57 } else { 58 handler.sendClientMsg("Echo : "+command); 59 } 60 } 61 } 62 | Popular Tags |