RDT 3.0 over UDP

This question will illustrate how a network application can achieve reliable data transfer without using TCP. It also should give a feel as to how TCP implements reliable data transfer.

Write a UDP client and server using the code in Chapter 2 as examples. The client (or sender) should read in a text file, chop it into sections of size 256 bytes and send each section as a packet to the server (or receiver) using the RDT 3.0 protocol. Recall that your packets should include a checksum and a sequence number (0/1). Also, you will need a timer. The receiver, of course, should return ACKs. The client should record (i) how many packets it sent, and (ii) how many were lost or corrupted. The server should record how many corrupted packets it received.

Turn in hard copies of the code for the client and server. Also turn in the recorded statistics for an execution of the programs on a large-ish file (/usr/share/dict/words on unix hosts, for instance).

1. You are supposed to compute the checksum yourself. You should do the same computation that UDP does (that is, add up 16-bit segments, do wrapping carry), but you don't have to worry about the 1's complement. Perhaps the easiest way to do this comptutation is to convert each byte of the input file to a number between 0 and 255 and then use *,+ and mod to get the numerical value of the checksum. Once you have this numerical value, you can store it in the packet in any way you want (that is, it can occupy more than 16 bits).

2. In this context, experiencing "natural" loss or corruption of packets may be very difficult. If this is the case, to simulate these you should take the following two steps: on the sender side, the sender should replace the actual checksum by 0 with probability 1/10. The receiver should ignore each received packet with probability 1/10. To implement this probabilistic procedure, you can do the following check:

if (System.currentTimeMillis() mod 10 == 0) then { ..... }

3. UDP's receive() function comes with its own timeout functionality. See the discussion of setSoTimeout() in the following documentation: UDP Socket Documentation.