TDC 368: Unix and Network Programming, Winter 09
Assignment 3: TCP/UDP Client
Due: 11:59pm Monday, 16 May 2009
Assignment Description
Measuring the
Round Trip Time is very useful for predicting network condition or estimating
the timeout over the Internet. In this
assignment, you will write a TCP or UDP client that measures the RTT value to three
different machines located in the US,
Europe and Asia. The host name will be read from the command line argument. Your client will send a message to each remote ECHO server in
each machine and measure the time it takes to receive the message back. RTT is
the elapsed time between sending (writing) the
echo message and receiving it back (read) by the
client. In case of UDP, you need to use SIGALRM to avoid any
deadlock or blocking-for-ever condition that your client might get into as a
result of using UDP (Why?). The Timer routine is provided to assist you in this
task. You must measure RTT for THREE different machines and print the result in
the standard output. The program should be run as follows: Mrtt "machine1" "macine2" "machine3" (where machine is either machine name or IP address).
Submission
Procedure:
Write your name and SSN in the main program and in the README file. After cleaning your directory from objects and bin files, do the following: (Your submission must contain a Makefile and a README file that describes how to run your program). You must use the same naming convention and command line arguments as specified in the assignment description.
$ tar
-cvf
<MNLABLogin>-<SSNLast4>-hw3.tar *
$gzip <MNLABLogin>-<SSNLast4>-hw3.tar
DO
NOT for get to take out any binary or object files in your submission
Then use DLWEB to submit your program .
Grading Policy
Late penalty is 10% per day.
Timer Program
In order to calculate the RTT, simply follow the next steps (the complete code/example is available in the home page under Resources link):
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define GETTIME(x) gettimeofday(x,NULL)
struct timeval starttime;
struct timeval endtime;
double totaltime;
printf("Timer started .........\n");
GETTIME(&starttime);
Insert the code/procedure that its
execution is to be measured
|
GETTIME(&endtime);
printf("Timer ends .........\n");
totaltime = (double)((endtime.tv_sec-starttime.tv_sec)+
(0.000001*(endtime.tv_usec - starttime.tv_usec)));
printf("TotalTime as measured by timer=%g sec\n", (double) totaltime);
NOTICE:
For compilation, you have to link with ucb library for gettimeofday(). you can add this into your make file or do the command line compilation as follow:
uranus% gcc -o mytimer mytimer.c -lucb
uranus% mytimer
Will Sleep for 4000000 useconds
Timer started .........
Timer ends .........
TotalTime as measured by the timer=4.00128 sec