CS 145A Lab 2 (due: Nov 7th)

Reliable Transmission over Unreliable Channel (I): Packet

Tasks for Lab 2

Assume there is no ¡°packet corruption¡± ("packet corruption": Bit error inside a packet. Bit error can be detected or even corrected by checksum. Details about error correcting codes can be found in EE127.)

This lab does NOT require network programming. We use file I/O to simulate network I/O.


The parameter format of the sender is: "sender <filename> <PacketSize>", where <filename> is the name of the file for "transmission", <PacketSize> is the maximum size of a packet (including header). The size of the file is smaller than 64M bytes. The file contains English characters and numbers only.

The sender should implement the following functions:


The parameter format of the receiver is: "receiver <number of ¡°packets¡±> <PacketSize> <filename>", where <number of "packets"> is number of files for packets "received" by the receiver side. The files are in order of: "P0000001.txt", "P0000002.txt"... However, the packet in each file may not be the same packet "sent" by the sender, due to "packet loss", "packet reordering" and/or "packet duplication". <filename> is the file that the receiver should write to.

The receiver should implement the following functions:


Assume we have a file with 7 characters: ¡°abcdefg¡±. The Packet Size is 10 bytes.
If the packet header in your design has a size of 7 bytes, the payload of each packet is 3 bytes.
So, the sender should output 3 files:
P0000001.txt: <header>+ ¡°abc¡±
P0000002.txt: <header>+ ¡°def¡±
P0000003.txt: <header>+ ¡°g¡±

If these three files are provided to the receiver without change, the receiver should output a file with 7 characters "abcdefg".

If packet 1 is lost, the receiver will see:

P0000001.txt: <header>+ ¡°def¡±
P0000002.txt: <header>+ ¡°g¡±

(Note that the file names are still sequent numbers.)

The receiver should output a file with 5 characters: "#defg". "#" indicates a packet loss.


Please submit your codes in "sender.c","receiver.c" or "sender.cpp","receiver.cpp", and your documents in "readme.txt"