Java Reference
In-Depth Information
4. Servers are supposed to run for a long time without stopping—therefore, they must be
designed to provide good service no matter what their clients do. Examine the server
examples ( TCPEchoServer.java and UDPEchoServer.java ) and list anything you can think
of that a client might do to cause it to give poor service to other clients. Suggest
improvements to fix the problems that you find.
5. Modify TCPEchoServer.java to read and write only a single byte at a time, sleeping one
second between each byte. Verify that TCPEchoClient.java requires multiple reads to
successfully receive the entire echo string, even though it sent the echo string with one
write() .
6. Modify TCPEchoServer.java to read and write a single byte and then close the socket.
What happens when the TCPEchoClient sends a multibyte string to this server? What is
happening? (Note that the response could vary by OS.)
7. Modify UDPEchoServer.java so that it only echoes every other datagram it receives. Verify
that UDPEchoClientTimeout.java retransmits datagrams until it either receives a reply or
exceeds the number of retries.
8. Modify UDPEchoServer.java so that echomax is much shorter (say, 5 bytes). Then use
UDPEchoClientTimeout.java to send an echo string that is too long. What happens?
9. Verify experimentally the size of the largest message you can send and receive using a
DatagramPacket .
10. While UDPEchoServer.java explicitly specifies its local port in the constructor, we do not
specify the local port in UDPEchoClientTimeout.java . How is the UDP echo client's socket
given a port number? Hint: The answer is different for TCP.
Search WWH ::




Custom Search