The assignment is to create a “chat” application, using the client/server
architectural model. The chat system consists of two main distributed
components: chat server and chat client, which may run on different hosts
in the network. Chat clients are Java programs which can connect to a
chat server.
The chat server is a Java application which can accept multiple incoming
TCP connections. The chat server maintains a list of current chat rooms
and chat clients can move between chat rooms. Messages sent by a chat
client are broadcast to all clients currently connected to the same chat
room.
Chat Server
In a nutshell, the chat server is primarily responsible for managing all the
chat clients currently connected to the chat server and for distributing
chat messages.
The chat server listens for requests from clients for making new
connections. When a client connects to the server:
• the server generates a unique id for the client which is guest followed by the
smallest integer greater than 0 that is currently not in use by any other
connected client, e.g. guest5
• the server tells the client its id using an NewIdentity message
• the server adds the new client to the MainHall chat room • this involves sending
more messages which is explained later
The protocol that the chat server must follow is specified exactly later in
this project specification. All of the message types are specified exactly as
well.
Client Command Line Interface
The client must accept input from standard input. Each line of input
(terminated by a newline) is interpreted by the client as either a command
or a message. If the line of input starts with a hash character “#” then it
is interpreted as a command, otherwise it is interpreted as a message.
The client must write all output to standard output. Since chat is
asynchronous, messages may arrive at any time and will be written to
standard output when they arrive.
This project will specify exactly what commands are possible, how they
should be interpreted and what should be output to standard output.
Example Client Session
Here is a quick example of how the client session may look:
$java -jar chatclient.jar localhost
Connected to localhost as guest5.
MainHall: 6 guests
comp90015: 14 guests
FridayNight: 8 guests
guest5 moves to MainHall
MainHall contains guest1 adel chao* guest34 guest2 guest5
[MainHall] guest5> #join comp90015
guest5 moves from MainHall to comp90015
comp90015 contains …
[comp90015] guest5>
guest8: we have a newcomer to the group!
Hi everyone
guest5: Hi everyone
[comp90015] guest5> bye
guest5: bye
[comp90015] guest5> #quit
guest5 leaves comp90015
Disconnected from localhost
Note that the example above was manually constructed and as such there
may be slight differences with the actual program output. It’s just an
example.
JSON Format
All protocol messages, i.e. sent between client and server, will be in the
form of newline terminated JSON objects.
A JSON library must be used to marshal JSON output and to unmarshal
JSON objects. Do not implement JSON (un)marshalling yourself.
All data written to the TCP connection must be UTF8 encoded.