Assignment 3: Chat room
Due: 5:00pm, Friday, October 11. Value: 40
In this assignment, you'll complete the portion of a chat client program
that handles communication with a server. The program consists of four
|Contains a |
main method and all other code related to the server.
|Contains a |
main method for starting the chat client and all
other code related to the interface.
|Contains code for tracking what an individual client
knows about the chatroom and for encoding/decoding messages
to update this state.|
|Contains code for communicating with the server.|
In testing this program, you'll want to ensure that the
program is running in the background before you start
You'll likely stop and start
times during debugging, but it should be OK to simply keep
running in the background.
ClientConnection class contains the only code
you will modify for this assignment, and the file containing it is the only
one you should submit.
The constructor should establish a connection
to the server and start a thread to process messages received
from the server.
send method will take a request provided by
ClientModel and send it to the server. Each message
sent to the server should be preceded by an
message identifier, which is a unique integer n.
(You can simply number each message starting from 0.)
The method should then await a server response:
The server could respond with
ok n”, in which case
null; or it could respond with
err n X”,
in which case
send should return the string X.
send method should not read this directly from the server,
but rather it will wait for the reading thread.
Please note that it should be possible for two threads to call
send virtually simultaneously; your method should accommodate
this except for necessary synchronization.
The server responses could easily arrive out of order.
Note: To send information to the server,
print the message to the
out — and then use
flush on the
PrintWriter so that whatever is buffered in memory is
sent to the server immediately.
run method is complete. It is the code
executed by the thread started in the constructor, and it repeatedly reads
and process lines read from the server.
It breaks each line into three pieces — the operation code,
the first argument (which could be the message ID to which the
server is responding), and the second argument (which could be
the error message). It then passes these to
Upon receiving a
processMessage method should
send method that sent the message.
For other types of messages,
should forward it to the
You can use any concurrency facilities packaged with Java to use
to complete this assignment.