Homework 2 : Multi-Threaded TCP server and Client

The purpose of this assignment is to give you some experience writing multi-threaded TCP servers and their clients.

1. Complete the server we started in Class

Complete the map server we started during lecture by implementing the protocol commands for put key value and get key. Note that as originally posted, the incomplete server had a couple of bugs in it. Make sure you download the correct version, which was uploaded at the same time as this assignment.

Add a help command to the protocol. When the client sends the command "help", the server responds by sending the a single line consisting of an integer, the number of protocol commands supported, followed by the syntax of each supported protocol command on its own line.

Test the server to make sure it works correctly. Open two different PUTTY windows or Telnet sessions and verify that the server can handle more than on client concurrently.

2. Write the Client

The client program is a console Java Application. Upon starting, it prints a welcome message :

      Welcome to the MapService Client

After this, the client program asks for the IP address of the server. The client assumes that the server is operating at port 50000. The client then connects to the server and displays the welcome message from the server. The client then prints a prompt for the user to enter a command to send to the server.

All user commands are entered on a single line. The client stays in a loop reading a command typed by the user, sending the command to the server, and reading and displaying the response. You must make sure that multi-line responses from the server are displayed correctly. The client terminates after it has received and displayed the response for the user's bye command.

Here is a sample interaction between the client and the server, as seen from the client's side:

Welcome to the MapService Client
Enter the IP address of the server: localhost
Please wait while I connect you...
Welcome to the map service.
Map service>mappings
a 1
b 1
aaa a 5
Map service>put North Central College 2014
Map service>keyset
[a, b, aaa a, North Central College]
Map service>get North Central     College 
Map service>help
get key
put key value
Map service>values
[1, 1, 5, 2014]
Map service>bye
See you later.


You cannot run multiple copies of the server, because all copies run at the same port and a port can be used by only one program at a time.

You can run both of your client and server from inside of Netbeans by right-clicking on the name of the file and selecting "Run File".

Due Date

Saturday night at the end of Week 4.