Homework 4

In this homework, we implement reliable communication over a highly unreliable link. The homework template is available at:


Your job is to change the template so that the following example execution always produces the correct result. In one terminal, you run the receiver in the following way, and it produces output as shown below.

./hw4_receiver 10080 > RECEIVED_FILE
UR: Minimum delay for this run is 274 ms
# later on, this happens...
File received, exiting.

In a separate terminal, you run the sender:

cat ORIGINAL_FILE | ./hw4_sender 10080
UR: Minimum delay for this run is 634 ms
Sent 1020544 bytes in 25 seconds: 35 kB/s
Estimated RTT: 1029 ms

For this homework, you can only have a single outstanding packet at any time. If you send a second packet before the first one arrives at the destination, the first packet will get 'clobbered', so it is important that you get your timeouts and your acknowledgments right.

A few things to pay attention to:

  • unreliable.{h,c} - do not edit these files: your turned in homework will be graded with a different unreliable.c. You can only depend on what is declared in unreliable.h
  • hw4_sender.c, hw4_receiver.c - these are to be thought of as 'applications', using the 'library' you implement in hw4.c. You may change these files, but it is unlikely that you would want to put significant new code in these.
  • hw4.c - this is where the majority of your code should go. You will need to make major changes to rel_socket(), rel_send(), rel_receive() and rel_close().
  • ur_socket(), ur_send(), ur_sendto() and ur_recvfrom(). You must use these calls to create your sockets and to send your packets. No sendto(), recvfrom() or connect() calls anywhere except in unreliable.c
  • The file transferred: your program should work for any file, and reproduce it exactly. You can check this with the md5sum utility, or diff.
  • The RTT: you are to dynamically estimate the RTT using the EWMA technique, and use this to set your timeout period. With correctly tuned timeouts, lower RTT will result in higher throughput.
  • Keep your packets smaller than or equal to MAX_PACKET (1400 bytes).


  • Pay attention to the end of the connection. Ensure that both sides of the connection finish without user assistance, while guaranteeing that the entire file is transferred. Look at the FIN/FINACK/ACK sequence in TCP for ideas.


  • For trying out your code, you can tune the packet loss ratios and round-trip latencies by changing LOSE_ONE_OUT_OF and MIN_DELAY_IN_MSEC in unreliable.c
  • Note that unreliable.c will be overwritten with a new version upon grading, so changes to these files are just for your own testing.
  • In rel_close(), you may want to just wait for some time, to make sure the last ack didn't get lost (leaving one end hanging).
  • ur_recv() is a blocking function, and making it non-blocking with SO_NONBLOCK or SO_RECVTIMEO options, or breaking it with alarm, is likely to give you trouble with the unreliability-abstraction (there is a delay imposed after receiving the packet). To safely implement a timeout, use select(), as follows:

fd_set readset;

struct timeval t = timeout; // select changes the timeout parameter on some platforms, so make a copy
int rdy = select(FD_SETSIZE,&readset,0,0,&t);
if rdy == 1, your socket is ready for reading, if 0 it timed out.

Turn-in instructions

Same story as previous homeworks, except that your makefile should generate two binaries called hw4_ receiver and hw4_sender.

This topic: CS450fall10 > WebLeftBar > Homeworks > Homework4
Topic revision: r1 - 2010-09-20 - 16:41:11 - Main.jakob
Copyright 2016 The Board of Trustees
of the University of Illinois.webmaster@cs.uic.edu
Helping Women Faculty Advance
Funded by NSF