Project 2 - Reliability Over UDP

Due - Monday, April 9, 2007

This project will give you experience implementing a reliable application-layer protocol over UDP. While your protocol will not be as complex as TCP and will not operate at the transport layer, this assignment will give you an appreciation for the difficulty associated with implementing a three-way handshake and acknowledgment scheme.

Your program will implement a simplified photo sharing application that uses UDP as its transport layer protocol and implements application-layer reliability. You may simplify the program you implemented for Project 1 by restricting the request messages that the server can process to only the get random photo. Your server will wait, in a loop, for a client to initiate communication (begin a three-way handshake). Once communication has been established, the client will send a request and your server will respond by selecting a random photo and sending it in 256-byte chunks. This means that you may not be able to send the entire message at one time. Your client must acknowledge each chunk as it receives it so that the server knows that all data has been received without error.

Your reliability protocol should be very similar to the alternating-bit protocol. However, you may assume that bits in the packet will not be corrupted. In other words, if a packet arrives at the receiver, you can assume that the packet is error-free. However, a packet may be lost entirely and never arrive at the receiver. In addition, duplicate packets may arrive. Therefore, you must make sure that each packet is the expected packet. An error-free run of your program should behave as follows:
1. Client sends "SYN" packet.
2. Server receives "SYN" packet.
3. Server sends "SYNACK" packet.
4. Client receives "SYNACK" packet.
5. Client sends "REQUEST" packet.
6. Server receives "REQUEST" packet.
7. Server sends "DATA" packet with first 16 bytes of data and sequence number 0.
8. Client receives "DATA" packet with sequence number 0.
9. Client sends "ACK" packet for data with sequence number 0.
10. Server receives "ACK" packet for data with sequence number 0.
11. Server sends "DATA" packet with next 16 bytes of data and sequence number 1.
12. Client receives "DATA" packet with sequence number 1.
13. Client sends "ACK" packet for data with sequence number 1.
14. Server receives "ACK" packet for data with sequence number 1.
15. Server sends "DATA" packet with next 16 bytes of data and sequence number 0.
16. Client receives "DATA" packet with sequence number 0.
17. Client sends "ACK" packet for data with sequence number 0.
18. Server receives "ACK" packet for data with sequence number 0.
19. Server sends "FIN" packet.
20. Client receives "FIN" packet.
21. Client sends "ACK" packet.
22. Server receives "ACK" packet.
23. Server closes connection.
24. Client closes connection.
However, your program must be robust enough to handle the loss of any packet. You should accomplish this by using timeouts and retransmissions. If the sender (which can be either the client or the server) sends a packet, it then waits for a response from the receiver. If it does not receive the response in a reasonable amount of time, it should resend the packet. It is up to you to decide how many times a packet should be resent before the sender simply closes the connection.

Implementation Requirements and Hints

  1. You may implement a single-threaded server. However, the problem with this implementation choice is that several clients could send messages to the server simultaneously causing the server to respond inappropriately to some clients. To handle this situation, during the three-way handshake your server must save the IP address of the client with which it is communicating. For the duration of the session (until a FIN is sent and the connection is closed), the server must verify that all packets it receives are from the appropriate client. If the server receives a message from a different client, it should disregard the message.
  2. When a receiver receives a message, it must verify that the message if of the expected type. For example, if the client expects a DATA message and it receives a SYNACK, it should respond appropriately. One appropriate response might be to ignore the message.
  3. The client should discard duplicate packets. Because your protocol uses retransmissions, it is possible that the client will receive two or more of the same packet. Make sure to check the sequence number of each packet as it arrives and do not process the same packet twice.
  4. The DatagramSocket class provides a setSoTimeout method. You should use this method so that your receiver does not wait indefinitely for a response from a sender. After the specified timeout period, an exception is thrown and you can retransmit or take appropriate action.
  5. The DatagramPacket class provides a getAddress method and a getPort method. You can use these methods to determine the address of the sender and the port on which it will be listening for a response.

Due 5:30PM Monday April 9, 2007

  1. Complete and submit your working code. Place a copy of your .java files in /home/submit/cs336/username.
Note: No portion of your code may be copied from any other source including another text book, a web page, or another student (current or former). You must provide citations for any sources you have used in designing and implementing your program.

Sami Rollins