The chat facility will in the client application sends messages to the chat server
so this must be running on the server machine.
"Name", "Bye" and "Send" messages are used to communicate with the chat server.
When the user logs on to chat a "Name" message is sent to the Messenger object.
Messenger sends a "Name" message to the chat server which returns the vector wList.
wList is a vector of the names of logged in chatters.
Next a "READY" message is sent to the messenger object. This causes a new thread
to be set up which listens on a different port for Message objects from the server.
When a message is typed in and the send button clicked a message is sent to the
chat server. The message is an array of strings.
The first string is "CHAT" which causes the server to make a message object and
send it to the new port on the client.
If a user disconnects from chat they are removed from the phonebook.
The phonebook is a static object that keeps state while the server runs. If the
chat server is restarted a new phonebook is initialised. The phonebook keeps the
details of each logged in chaters connection.
Sending and listening are handled differently in the client application.
Messages are sent by calling the Messenger send message method but messages from
the server are received by an inner class Chat which extends thread.
When a chatter logs on or off the chat server the server sends a "LIST" message
to the client with the updated list of chatters in the phonebook.
There are no message queues so if someone sends a message and the recipient logs
off they do not receive the message later. Messages can only be sent to logged on
chatters. Any number of messages can be sent and received in any order. Each message
is only sent to one other client. Chat partners can be changed at any time.
A message is delivered to the recipient with the sender's name attached.
There is no GUI for the chat server and the message 'chat server started' is sent
to standard output. A small GUI to start and stop servers and maybe change ports
could be added as an additional feature.