01: /*
02: * This file is part of the QuickServer library
03: * Copyright (C) 2003-2005 QuickServer.org
04: *
05: * Use, modification, copying and distribution of this software is subject to
06: * the terms and conditions of the GNU Lesser General Public License.
07: * You should have received a copy of the GNU LGP License along with this
08: * library; if not, you can download a copy from <http://www.quickserver.org/>.
09: *
10: * For questions, suggestions, bug-reports, enhancement-requests etc.
11: * visit http://www.quickserver.org
12: *
13: */
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,
25: ClientEventHandler {
26: private static Logger logger = Logger
27: .getLogger(EchoCommandHandler.class.getName());
28:
29: //--ClientEventHandler
30: public void gotConnected(ClientHandler handler)
31: throws SocketTimeoutException, IOException {
32: logger.fine("Connection opened : " + handler.getHostAddress());
33:
34: handler.sendClientMsg("+++++++++++++++++++++++++++++++");
35: handler.sendClientMsg("| Welcome to EchoServer v "
36: + EchoServer.version + " |");
37: handler.sendClientMsg("| Note: Password = Username |");
38: handler.sendClientMsg("| Send 'Quit' to exit |");
39: handler.sendClientMsg("+++++++++++++++++++++++++++++++");
40: }
41:
42: public void lostConnection(ClientHandler handler)
43: throws IOException {
44: handler.sendSystemMsg("Connection lost : "
45: + handler.getSocket().getInetAddress(), Level.FINE);
46: }
47:
48: public void closingConnection(ClientHandler handler)
49: throws IOException {
50: logger.fine("Connection closed : "
51: + handler.getSocket().getInetAddress());
52: }
53:
54: //--ClientEventHandler
55:
56: public void handleCommand(ClientHandler handler, String command)
57: throws SocketTimeoutException, IOException {
58: if (command.toLowerCase().equals("quit")) {
59: handler.sendClientMsg("Bye ;-)");
60: handler.closeConnection();
61: } else {
62: handler.sendClientMsg("Echo : " + command);
63: }
64: }
65: }
|