1 Synopsis
Assignment 1
FIT5010 2019 SM1
Online Dictionary
The assignment is to create an “online dictionary” application using client/server architecture. The system consists of two main distributed components: server and clients, which may run on different hosts in the network. Clients are Java programs which can connect to the server. The server is a Java application that accepts multiple incoming TCP connections from clients and returns the meaning of a word stored in a dictionary. In addition to seeking for the meaning of the words, the server allows clients to add, edit or remove words. The dictionary data is shared among all the clients.
This assignment has been designed to use TCP Sockets. The server creates a pool of threads and uses them to process clients requests.
2 Dictionary Server
The server maintains the dictionary. The dictionary contains the list of words and their meaning. The server must serve multiple clients concurrently. Threads are used to achieve this functionality. The server is also responsible for managing all the connected clients and responding to their requests. The server listens for connection requests from clients. As soon as a client is connected to the server, the server is ready to accept commands from the client. The command messages will allow the client to query, add, update, and delete words in the dictionary. All the communicated messages between the server and clients must be encapsulated in the form of JSON messages (more details to come).
3 Client
A client runs on the operating system command line with the following parameters: server name (server IP) and optional port number both as arguments of main(). The client establishes a TCP connection with the server using the provided arguments. Having the TCP connection established, the client can query the server for the meaning of a given word, add a new word with its meaning to the dictionary, removes a word from the dictionary, and updates the meaning of the word in the dictionary.
Table 1: List of Commands
command name
arguments
meaning
query
gueries the meaning of the
delete
removes the
add
adds the
update
updates the meaning of the
exit
disconnects from the server
1
In order to send a command, the client’s user should type a command name following with the required arguments (arguments are always surrounded by “<” and “>” and are separated from each other by space). Commands are sent by Enter (Return) key. The list of commands and their arguments are shown in Table 1. If a client gets disconnected, the server handles the situation as exit command. Commands, words and their meaning are case-sensitive.
Proper Error messages are generated by the server in the case of wrong command, e.g. if a client tries to remove a word that does not exist or sending unknown command. Any error should be responded with either of messages shown in Table 2.
Table 2: Error messages
error message
condition
The word does not exist.
The word does not exist for query, update, or delete.
The word already exists.
The word already exists in the dictionary if client tries to add the same word.
Wrong command.
Unknown command or wrong command message, missing or extra arguments.
Unknown error.
Any other errors.
Here is an example of how a client session may look:
E:\>java -jar client.jar -h localhost -p 4444
query
The word does not exist.
add
query
an act of giving one thing and receiving another
update
trade
remove
Wrong command.
exit
4 Protocol Specification
All messages exchanged between client and server must be encapsulated in the form of UTF-8 encoded JSON messages that ends with the newline charterer (“\n”) .
JSON format for messages sent by a client is as follows:
{
“command”:”command name”,
“arguments”:[list of arguments]
}
For example the update command message is sent as:
{
“command”:”update”,
2
“arguments”:[“exchange”,”an act of giving one thing and receiving another”]
}
or exit command as
{
“command”:”exit”,
“arguments”:[]
}
The server’s responses are either error or response in the following format:
{
“type”:”error/response”,
“message”:”text”
}
“text” is the error message in the case of errors. For all commands that are successfully performed “text” is “done”, except query command that “text” contains the meaning of the queried word.
For example:
{
“type”:”response”,
“message”:”an act of giving one thing and receiving another”
}
Other sample messages:
{
“type”:”error”,
“message”:”Unknown error.”
}
or
{
“type”:”response”,
“message”:”done”
}
5
• •
•
Technical aspects
Use Java 1.8 or later.
All message formats should be UTF-8 JSON encoded. Use a JSON library for this (e.g., jsonsimple library).
Your program should be cleanly finished by terminating all running threads. 3
6
• •
• • •
Package everything into a single runnable jar file, one for server, one for client.
Your server and client should be executable exactly as follows:
java -jar server.jar [-p port]
java -jar client.jar -h hostname [-p port]
Square brackets ([]) indicate that what is inside the bracket is optional.
Use command line option parsing (e.g. using the args4j library or your choice).
The default server port should be 4444. A command line option [-p port] can override this. Pressing Ctrl-C should terminate either client or server.
Report
Write 200 words at most for each of the following questions:
• In this project, we used TCP protocol for the communication between the client and server. Give
two reasons for and two reasons against using UDP instead.
• Suppose you run client before you run server. What happens? Why?
• Explain why we only need server’s port in the online dictionary application? Explain how server knows the client’s port to send a response?
Use 12pt times font, single column, 1 inch margin all around. Put your name, login name, and student number at the top of your report.
7 Submission
You need to submit the following via Moodle: • Your report in PDF format only.
• Your server.jar and client.jar files. • Your source files in a .zip archive only.
Submissions are open and due in 11:55pm 18th of April.
4