As with our previous client-server examples, the server program will take exactly 1 command line argument, specifying the port on which it will be listening. The client program will take exactly 2 command line arguments, specifying the name of the machine on which the server is running, and the port on which the server is listening. Following is an example of the outputs when the server is running on the machine blackbird.dickinson.edu, and the client is run on the machine albatross.dickinson.edu.
First, we start the server on blackbird:
blackbird:/tmp jmac$ java TimeServerP3 56765
Then, we run the client on albatross:
albatross:/tmp jmac$ java TimeClientP3 blackbird 56765 TimeServer at blackbird says time is 15:20:19
Your solution should contain exactly 2 files, called TimeServerP3.java and TimeClientP3.java. If you define any other classes, add them to one of these files as we did with the MyHttpRequest class in assignment P2. Submit your code to Web-CAT by first making a zip file of these two Java files.
To achieve this, the client program must accept an additional optional parameter. If this parameter is present, it should be in the format HH:MM:SS, representing the time in hours, minutes, and seconds, where the hours are specified using the 24-hour clock. If the extra parameter is present, the client program performs a SETTIME request, otherwise it performs a GETTIME request.
For example, assume that the server has been started on blackbird.dickinson.edu as above. Then just as before, we might run the client on albatross.dickinson.edu. Issuing a GETTIME produces the same behavior as before (assuming the current time is around 3:20 p.m.):
albatross:/tmp jmac$ java TimeClientP3 blackbird 56765 TimeServer at blackbird says time is 15:20:19We might then issue a SETTIME, setting the server's time to 9:45 a.m.:
albatross:/tmp jmac$ java TimeClientP3 blackbird 56765 09:45:00 TimeServer at blackbird completed SETTIME requestFinally, we wait for exactly 100 seconds and issue another GETTIME:
albatross:/tmp jmac$ java TimeClientP3 blackbird 56765 TimeServer at blackbird says time is 09:46:40Note that the server's time is now 100 seconds later than the 9:45 a.m. to which it was set, 100 seconds ago.
A note on the implementation: do not attempt to reset the system clock on the machine where the server is running. Instead, the server should merely remember the offset between its own "virtual" clock, and the system clock.