Create a directory server in Java called DirectoryServer.java. You may include other files/classes as you see fit.
A directory server keeps track of clients logged into a peer-to-peer system. Its purpose is to allow clients to look up other clients that are logged on so a direct connection can be made between the two clients. The server does not make the connections between clients, it just provides information about each client. This server will listen on port 54321.
This directory server will store the following information about each of the clients:
The protocol for client-server interaction is as follows:
Note that connections are NOT persistent. The client connects to sign on to the system and immediately disconnects. Being signed on to the system is not the same as being connected to the server. Since connections consist of issuing a single command only, the server does not need to handle simultaneous connections.
Use netcat to connect to your server and test both correct and erroneous communication.
The server should respond to the commands LOGON, PING, LIST and LOGOFF. Notice the commands sent from client to server are delimited by space characters and the replies are delimited by colons. Both requests and responses end with a newline character.
The LOGON command should add the client's information to the list of clients. The server will get the host IP information from the Socket. The port specified here will be the port that clients use when they communicate with each other.
| LOGON | (space) | port | (space) | name | \n |
The reply should be of the form:
| ADDED | : | id | : | ttl | \n |
Where id is a server assigned identification number for the client. The client application will use this id when making other requests. ttl is the time, in seconds, the client's entry will exist before it is removed.
| PING | (space) | id | \n |
The reply is of the form:
| PONG | : | ttl | \n |
where ttl is the new time to live (in seconds) provided by the server.
The LIST command tells the server to generate a list of all clients connected to the directory server. The client must include its id, so the server knows it is a valid client.
| LIST | (space) | id | \n |
The reply consists of a header line that includes the number of clients logged on (n), which will also indicate the number of lines that follow (one for each client).
| LIST | : | n | \n | ||||
| ID | : | name | : | host | : | port | \n |
| ... | |||||||
| ID | : | name | : | host | : | port | \n |
The logoff command should remove the client from the list of clients and invalidate its id.
| LOGOFF | (space) | id | \n |
The reply is of the form:
| DONE | : | id | \n |
The server should respond to erroneous commands as shown below. The message portion can be any string (but should not contain ":" or new lines).
| ERROR | : | MESSAGE | \n |
The server should be able to handle errors gracefully and continue to run.
Turn in the file DirectoryServer.java: a documented Java implementation of the server.
Your program will be graded on the following criteria:
While testing your program I will need to adjust the time to live value, make sure it is defined as a constant.
In case you are interested in developing the client and server at the same time, the next assignment will be a DirectoryClientConnector class and test program.