Lab 03: Experiment with TCP and Comparing among Different Programming Languages

Goals

Credits

The material developed for this lab was developed by Professor Felipe Perrone (Bucknell University) with some revisions by Professor Meng (Bucknell University). Some of this lab is based on material from Unix Network Programming Volume 1, by W. Richard Stevens, Bill Fenner, and Andrew M. Rudoff (Addison Wesley, 2004).

Permission to reuse this material in parts or in its entirety is granted provided that the credits note is not removed. Additional students files associated with this lab, as well as any existing solutions can be provided upon request by e-mail to perrone[at]bucknell[dot]edu.

Setup

Create a directory in your Git repository called lab03, as in

~/csci363/labs/lab03

Use the client-server program example in the lecture example directory as the base for your program.

Problem 1: The pingpong application

In this problem, you will create a pair of client-server programs called pingpong.c and reflectord.c, which communicate using TCP byte streams. The general idea is that pingpong will create a message of a given length, transmit it to reflectord, which sends the same message right back to pingpong.

(A) You will need to instrument the pingpong to send a number of messages of a given size to another program reflectord and wait for it to come back. You are asked to measure the following metrics.

These time measurements can be obtained from placing calls to gettimeofday(2) in right places in your program. If you take these samples for each message sent from pingpong to reflectord, at the end of pingpong's execution you will report four values:

The command line for pingpong should be as follows:

pingpong num_msgs msg_length host port

where:

Running the program from a shell should look like:

$ pingpong 50 10000 machine.eg.bucknell.edu
One or more parameters missing.
Usage: pingpong [num_msgs] [msg_length] [host] [port]
$ pingpong 50 10000 machine.eg.bucknell.edu 9010
0.001 0.034 0.002 0.038

In this example, 0.001 represents the average time to create a TCP connection, 0.034 represents average the time to send and get back a message of 10,000 bytes, 0.002 represents the average to tear down a TCP connection, and finally 0.038 represents the average of the total time to create a connection, send and receive the message, and tear down the connection (with all averages computed over 5o samples). All time are in mili-seconds.

(B) Your second program, reflectord, will be a daemon, that is, a server listening at an agreed-upon port and running in an infinite loop. This program should be very simple: wait for a connection request, establish the connection, listen for an incoming message, return the identical message to the sender, and go back to waiting for the next message. It is not critical whether or not you create a child process to handle the application in this lab.

The command line for reflectord should be as follows:

reflectord port

where:

Create a Makefile for compiling your two programs. Also, make sure to use your wrappers.h and wrappers.c from last week when appropriate and to augment them if you use any new system or library calls that you could wrap.

Test your program by running the program with a few different sets of parameters, different number of repetition, different size of messages. Also run your server program and client program on different computers.

When you're done with this problem, you need to do:

Problem 2: Comparing measurements from different programming languages

Programming language C usually is considered very fast, time efficient in execution. In this part of the lab, you are asked to assess the performance of C by comparing with other two programming languages, Python and Java, when doing similar type of work, i.e., establishing and tearing down TCP connections, sending and receiving messages of various size.

You are given a set of client-server programs written in Java and Python. Copy the programs to your local lab directory, run the program with various input sizes, record the time needed to complete the tasks to compare with what C program can accomplish.

When you're done with this problem, you need to do:

Congratulations, you've finished this lab!