ICS 451 Assignment 6: Alternating Bit Protocol

Assigned February 24th, to be completed by March 3rd.

Turn in this exercise by e-mailing to jmoroney@hawaii.edu all your code.

You may do this assignment in groups of up to three. Your team cannot include anyone that was on your team in Assignment 5.

This assignment transfers a file from one machine to another, 100 bytes at a time (the last packet may be less than 100 bytes). Data bytes are sent over UDP, with a 1-byte header in front of the data. The header is described below.

You must write two programs, a sender.c and a receiver.c. Each program takes a file name as its only command-line parameter -- the parameter for the sender is the name of the file to send, the parameter for the receiver the name of the file to save as.

You must choose a UDP port for the receiver to listen on, and the sender should send to that port. The port number must be a constant defined in a header file used by both the sender and receiver:

#define PORT_NUMBER	0

(I purposely used an invalid port number as the example because I want you to choose your own port number).

The receiver must bind this port number. The sender should send to this port number on localhost ( -- but see below for options), using a UDP socket and sendto.

The sender must:

Correspondingly, the receiver must:

Turn in your code for these two programs. The code will include sender.c, receiver.c, the header file used by your two programs, and possibly other source files (as always, do not send binary files).

Measuring the size of a file

You may use the following code to measure the size of a file:

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

static long file_size (char * file_name)
  struct stat st;
  if (stat (file_name, &st) == 0)
    return st.st_size;
  return 0;

Testing retransmission

Normally, the receiver will be started before the sender.

The simplest way to test retransmission is to not start the receiver at all, or to start it some time after the sender. This way, the sender should keep sending the first packet over and over again.

To do more elaborate testing (not required for this assignment), you could drop a packet (instead of sending it) if, for example,

 time(NULL) % 10 == 0


If you wish, you may allow the sender to have a second parameter, the domain name or IP number of the machine on which the receiver is running, and send to that address instead of localhost.

If you wish, instead of reading the whole file and storing the contents into the malloc'd array, the sender may read the file 100 bytes at a time into a fixed 100-byte buffer (or 101-byte buffer), just send what it read, and repeat.

Computer Networks, ICS 451
Instructor: Edo Biagioni