01
// EchoCommandHandler.java
02
package
echoserver;
03
04
import
java.net.*;
05
import
java.io.*;
06
import
org.quickserver.net.server.ClientCommandHandler;
07
import
org.quickserver.net.server.ClientHandler;
08
09
public class
EchoCommandHandler
implements
ClientCommandHandler {
10
11
public void
gotConnected(ClientHandler handler)
12
throws
SocketTimeoutException, IOException {
13
handler.sendClientMsg(
"+++++++++++++++++++++++++++++++"
);
14
handler.sendClientMsg(
"| Welcome to EchoServer v 1.3 |"
);
15
handler.sendClientMsg(
"| Send 'Quit' to exit |"
);
16
handler.sendClientMsg(
"+++++++++++++++++++++++++++++++"
);
17
}
18
public void
lostConnection(ClientHandler handler)
19
throws
IOException {
20
handler.sendSystemMsg(
"Connection lost : "
+
21
handler.getSocket().getInetAddress());
22
}
23
public void
closingConnection(ClientHandler handler)
24
throws
IOException {
25
handler.sendSystemMsg(
"Closing connection : "
+
26
handler.getSocket().getInetAddress());
27
}
28
29
public void
handleCommand(ClientHandler handler, String command)
30
throws
SocketTimeoutException, IOException {
31
if
(command.equals(
"Quit"
)) {
32
handler.sendClientMsg(
"Bye ;-)"
);
33
handler.closeConnection();
34
}
else
{
35
handler.sendClientMsg(
"Echo : "
+command);
36
}
37
}
38
}
|