Chat server's principal class is ChatServer that listens on socket for new connections. It instantiates a new threaded client back-end for each new connection (as instance of the ChatServerClient class) and keeps all such client connections in the ChatServer.clients list. Client back-end thread purges itself from the list after remote end is disconnected.
ChatServerClient will receive messages in ChatServerClient.run() from the remote client and call-back servers's ChatServer.broadcast() method that will distribute message to all connected clients.
Server may also opriginate its own messages, which will be prefixed with the "[System] :: ".
After receiving "wwhhoo" message, server will broadcast a list of all connected clients in the form: WWHHOO: <client-hostname>:<port>
.
One can start application with the following command:
java -jar chatServer.jar [ <port> ]
where the default port is 2000
If the server detects that the user is alone in the chat-room, it will offer to user to talk to an instance of Joseph Weizenbaum's Eliza, a simulation of a Rogerian psychoterapist implemented by Charles Chayeden.
The server will start Eliza in respond to user message talk eliza
(ignoring spaces and character cases).
The jar file of the package can be found here.
Source files: