CS2105 Assignment 2
CS2105 Assignment 2
School of Computing
CS2105 Assignment 2 Semester 2 10/11
Deadline
27 March, 2011 (Sunday), 11:59pm.
Objective
In this assignment, you will implement a reliable transfer protocol on top of a unreliable channel
that can drop packets randomly (but always deliver in order and corruption-free).
Pre-requisite
You are expected to be familiar with the alternating bit protocol (rdt 3.0).
The assignment will be done under a controlled, UNIX environment. Familarity with UNIX
environment (how to copy/move/delete/edit files, how to compile and run programs, etc.) is
assumed.
Administrative Matters
This is an individual assignment.
An account has been setup for you on host cs2105-z.comp.nus.edu.sg. To access your ac-
count, ssh to the host and login using your SoC UNIX username and password from a SoC host
or through SoC VPN.
If you have any questions or encounter any problems with the steps discussed in the assign-
ment, please contact the teaching staff through CS2105’s blog.
Introduction
For this assignment, you are given the code for a receiver and sender for three network layers:
application, reliable transport (RDT), and unreliable transport (UDT).
The UDTSender and UDTReceiver classes simulate a networking layer that delivers packets
unreliably. Packet can get loss randomly. However, for simplicity, you can assume that this
layer delivers packets in order and never corrupts the packets.
The FileSender and FileReceiver classes are the application that we use for this assignment.
The FileReceiver basically is a server that waits for connection, receives a file, and saves the file
onto the disk with a given name. To run FileReceiver, use
For example,
listens on port 9000 for connection and dumps the bytes received into a file named foo.zip.
The FileSender program is basically a file uploader that connects to FileReceiver and sends
the data read from a given file to FileReceiver. To run FileSender,
For example,
File File
Sender Receiver
byte [ ] byte [ ]
RDT RDT
Sender Receiver
UDT UDT
Sender Reciver
Your Tasks
You are also provided with two classes, RDTSender and RDTReceiver, that interface between
the application (FileSender and FileReceiver) and the unreliable data transport (UDTSender
and UDTReceiver). RDTSender and RSTReceiver should employ techniques from Lecture 3,
including acknowledgement, retransmission, timeout, and sequence number, to make sure that
data to be delivered from “above” is sent correctly to the other side. You need not, however,
implement windowing nor checksum.
So, your task in this assignment is to modify the given RDTSender.java and RDTRe-
ceiver.java such that FileSender and FileReceiver will work correctly – the received file is exactly
the same as the file uploaded.
You should read the given set of source code carefully to understand the interaction between
the different classes. The code is documented and should be pretty self-explanatory. There are
only about 300 lines of code in total.
Figure 1 shows the overall relationship between the classes in this assignment.
How to Do It in Java
Timer
You will need two java.util.* classes to implement timeout. The Timer class schedules a task to
be executed periodically after a certain delay, while the TimerTask class implements the code
that you want to execute periodically. For example, to print a given number after 5 seconds,
and subsequently every 5 seconds, you create the following task,
Page 2
class NumberPrinter extends TimerTask {
int x;
NumberPrinter(int toPrint) {
x = toPrint;
}
public void run() {
System.out.println(x);
}
}
timer.cancel();
cp -r ~sadm/a2 .
Note that you must put your files inside the directory a2 directly under your home directory.
You will be responsible for the security of your own source code. Please be careful and set
the correct permission for your files. They should not be readable by anyone else except the
owner (chmod 600 *.java will ensure that).
Note that you will be running your FileReceiver on the same host, and therefore must use a
different port number. To prevent collision, you should avoid ”nice” port numbers such as 8000
or 8080.
Page 3
Submission and Grading
There is no need to submit the program by email or IVLE workbin. We will collect your
assignment from your home directory on cs2105-z.comp.nus.edu.sg when the deadline is over.
We will test your assignment automatically using a grading program. For this to work, you
must not modify other java files (except RDTSender and RDTReceiver) in any signficant way
(println of debugging statement is OK). If you suspect that there is a bug in these code, please
contact us by posting on the blog.
You MUST name your java program RDTSender.java and RDTReceiver.java. We will only
compile these two files when we grade. You MUST not implement additional classes in other
*.java files.
Plagiarism Warning
You are free to discuss the assignment with your peers. But, ultimately, you should write your
own code. We employ zero-tolerance policy against plagiarism. If you are caught copying from
other student, or let others copy your code, you will receive zero for this assignment. Further
disciplinary action may be taken by the school.
Grading
• 2 marks: Implement sequence number correctly.
We will deduct one marks for every failure to following instructions (wrong directory name,
wrong filename, etc.)
THE END
Page 4