Create two Java classes called DirectoryClientConnector.java and DirectoryTest.java. DirectoryClientConnector provides an API for connecting to the DirectoryServer from the previous assignment. DirectoryTest is a program that thoroughly tests the DirectoryClientConnector functionality.
The DirectoryClientConnector class should contain the following methods.
| Method | Description |
|---|---|
| public DirectoryClientConnector( String serverName, int port, String name) | Constructor for the class. It should store the name of the server and the port number to be stored by the server, as well as a "screen name" for the client. The constructor should not actually connect to the server. The port number specified here will NOT be used for a connection in this assignment. Do NOT use it to connect to the DirectoryServer. |
| public void logon() throws Exception |
Connect to the server and issue a LOGON command as described by the DirectoryServer. The object should store the server-assigned ID. The method should throw an exception if it fails to logon. Reasons for failure include this object being used to logon previously, without logging off, or the server responding with an error. Once logon is called DirectoryClientConnector should send a PING message frequently enough that the client is not automatically logged off by the server. This should be about halfway through the server specified time-to-live. Use a Thread or Timer to call ping until logoff is called for this connection. Recall that the server specifies a time-to-live in reply to every ping message. This value may change. |
| public ArrayList<String> getList() throws Exception | Connect to the server and issue a LIST command as described by the DirectoryServer. Return an ArrayList of Strings that store client information. Strings should be formatted in the same way that they are produced by the server. Throw an exception if it fails to produce a list. |
| public void logoff() throws Exception | Connect to the server and issue a LOGOFF command as described by the DirectoryServer. If the client has been sending ping messages because of the logon message, stop them. Throw an exception if it fails to log the client off. |
| private void ping() throws Exception | Connect to the server and issue a PING command as described by the DirectoryServer. Throw an exception if the ping produces an error. |
From the time the logon method is called until the logoff method is called, the client class should send a PING message to the server to keep the server from discarding the client's data. You may use a Timer or Thread to accomplish this.
The test program should simulate multiple clients and their interactions with the server to test both the DirectoryClientConnector and the DirectoryServer. It should do the following:
Turn in the following files
Your programs will be graded on the following criteria: