Java Reference
In-Depth Information
Exercises
2.1 If you haven't already done so, compile programs TCPEchoServer and
TCPEchoClient from Sect. 2.2.1 and then run them as described at the end of
that section.
2.2 This exercise converts the above fi les into a simple email server and email client
respectively. The server conversion has been done for you and is contained in
fi le EmailServer.java , a printed version of which appears on the following
pages for ease of reference. Some of the code for the client has also been
provided for you and is held in fi le EmailClient.java , a printed version of which
is also provided.
You are to complete the coding for the client and then run the server program
in one command window and the client program consecutively in each of two
further command windows. For the fi rst client, log in with one of the names
specifi ed below (i.e., 'Dave' or 'Karen') and send a few emails (fewer than 10)
to the other user. Then quit and run the client program again, this time logging
in as the other user and selecting reading of his/her emails. The full details of
this simplifi ed client-server application are given below.
￿ The server recognises only two users, called 'Dave' and 'Karen'.
￿ Each of the above users has a message box on the server that can accept a
maximum of 10 messages.
￿ Each user may either send a one-line message to the other or read his/her own
messages.
￿ A count is kept of the number of messages in each mailbox. As another message
is received, the appropriate count is incremented (if the maximum has not been
reached). When messages are read, the appropriate count is reduced to zero.
￿ When sending a message, the client sends three things: the user's name, the
word 'send' and the message itself.
￿ When requesting reading of mail, the client sends two things: the user's name
and the word 'read'.
￿ As each message is received by the server, it is added to the appropriate mail-
box (if there is room). If the mailbox is full, the message is ignored.
￿ When a read request is received, the server fi rst sends an integer indicating the
number of messages (possibly 0) that will be sent and then transmits the mes-
sages themselves (after which it reduces the appropriate message count to 0).
￿ Each user is to be allowed to 'send' and/or 'read' as many times as he/she
wishes, until he/she decides to quit.
￿
When the user selects the 'quit' option, the client sends two things: the user's
name and then the word 'quit'.
2.3 If you haven't already done so, compile and run the server program
DayTimeServer and its associated client, GetRemoteTime , from Sect. 2.3 .
Search WWH ::




Custom Search