G22.2262-001 Data Communications and Networks

Assignment 5

 

Due Date: December 14, 2006

 

Revision 0: November 22, 2006

Revision 1: December 1, 2006

o        Describe binary message handling in TCP

o        Give example of expected output

 

1.     Overview.

 

Write an echo server that will accept either TCP or UDP data and write the same message back to the source.  Keep track of message counts, run time, byte counts, and inter-arrival statistics and compute a final mean and max inter-arrival time for messages that you receive.

 

You may write this program in JAVA, C, or C++

 

As always, the NYU and class policy about plagiarism must be followed in this project.  If you use ANY code in your project that is not of your own creation, then you MUST attribute that code to the author, even if you modify it (ANY modification).

 

 

2.     Specification

 

2.1.   Operation

 

Your "echo" server should operate in either TCP or UDP mode, as determined by a command line argument.

 

In TCP mode, your server should accept TCP connection requests from a client.

 

In UDP mode you should simply read datagrams on the specified port.

 

Once the client has connected to your server (TCP), or at anytime following startup in UDP, it will send messages to you at a variable rate. You must write this data back (unmodified) to the client.  You must keep track of the inter-arrival times of messages from the client by computing the minimum, average, and maximum times between messages.

 

The inter-arrival times must be expressed in milliseconds.  To help you choose an appropriate internal representation for you mean statistic, you may assume that the maximum number of messages over which you must take the average is 1000.  I will look more favorably upon programs that can compute an accurate running average rather than storing a large array of values and computing the average of the array entries at the end.

 

 

NOTES: You should use a floating point data type for your average variable to avoid propagating round off error in your running average. You may display the final average inter-arrival time in floating point or integer (long) format.

 

Do NOT include the final termination message (see 2.2 below) in your statistics.

 

 

The port to use for your server and the mode (TCP or UDP) will be input as command line arguments.

 

The maximum size message that the client will send is 512 bytes.

 

The command line arguments MUST be accepted in the following form:

 

-m [t,u] ( t =TCP, u = UDP )

-p port

 

 

2.2.   Termination

 

Your program should stop reading messages from the client when the TCP or the UDP client sends a three byte message whose content is the ASCII text “end'.

 

DO NOT INCLUDE THE TERMINATION MESSAGE IN YOUR STATISTICS, AND DO NOT ECHO THE TERMINATION MESSAGE BACK TO THE CLIENT.

 

Upon termination print the following information.

 

·      Total number of messages received from the client.

·      Total number of bytes received from the client.

·      Total time of the run in seconds (beginning from receipt of first message).

·      Total number of bytes sent to client.

·      Minimum inter-arrival time (lambda) in milliseconds.

·      Maximum inter-arrival time (lambda) in milliseconds.

·      Mean inter-arrival time (lambda) in milliseconds.

 

 

2.3.  Binary Message Format

 

The EchoClient sends binary format messages, except for the termination message.  What this means is that you will not be able to use methods like readLine() in TCP mode.  Instead, you will have to use one of the binary read methods in whichever class you decide to use to read the InputStream from the client.

 

It is your task to figure out how to know when you have read an entire message given only what you know about the test environment and how the echo client works.  I’ll summarize that here for you:

 

o        You are running both client and server on the same machine, so there will be no network congestion.

o        Client sends messages that are guaranteed to fit in one MSS (lookup definition of MSS up if you don’t know what it means!)

o        Your application (the server) is dedicated to reading just that one socket from the client, so unless you have a really bad design (or bug), there is no reason that the TCP read buffer will ever contain any more or less data than exactly what the client sends in one segment.

 

Given this, you should read all of the available data from the socket until there is no more data available to read, meaning that the TCP receive buffer is empty.  At this point you should assume that you have a complete message.

 

It is your task to figure out how to use classes and methods in the Java IO package to accomplish this.  I suggest that you read about the InputStream class and the DataInputStream class and understand what ALL of the methods can do for you.  Remember – these are binary messages. 

 

Please DO NOT send questions to me or the class list asking which class or method to use.

 

 

2.4.   Use of Libraries/Packages.

 

 

/********* BEGIN COMER CODE **********/

/********* END COMER CODE ************/

 

The code from Comer is here.

 

 

2.5.  Sample Ouput

 

Here is an example of what you should print at the end of the run (after you see the termination message):

 

Messages rcvd: 214

Bytes received: 56620

Run time: 16370

Bytes sent: 56620

Min Lamda: 29

Max Lamda: 141

Lamda: 74

 

Here is the corresponding information from the EchoClient for the same run:

 

Messages sent: 214

Messages rcvd: 214

Bytes sent: 56620

Bytes received: 56620

Run time: 16372

Delay total: 15653

Min Lamda: 29

Max Lamda: 139

Lamda: 73

 

 

3.     Evaluation

 

This assignment is worth 20 points.  You will be graded on both the completeness and accuracy of your program, as follows.

 

·         Accept and send data in both TCP and UDP:                 8 points

·         Quality of design:                                                                                2 points

·         Compute min, max, mean to within 20% of actual:          1 point

·         Compute min, max, mean to within 10% of actual:          1 point

·         Echo correct number of messages (UDP only):                              1 point

·         Echo correct number of bytes:                                           1 point

·         Handle termination correctly:                                             1 point

·         Answers to questions (see section 5 below)                 5 points

 

I will supply you with a message-generating client that you may use to help test your program.  It will help you determine if your program is working correctly.  The tester will display the total number of messages sent, the total number of bytes transmitted to you, the total time of its operation, and the min, max, and mean values of its inter-transmission time.

 

       The EchoClient program, written in JAVA, is here.   It is an executable JAVA jar file (EchoClient.jar)

 

 To use the program, use this command:

 

java -jar EchoClient.jar -m <t/u> -p <port>

 

where -m selects mode (t = TCP, u = UDP) and <port> is the port number that your server is using.

Remember to start your server BEFORE you run the EchoClient!

 

For example, to run the EchoClient in UDP mode using port 5555, enter:

 

java -jar EchoClient.jar -m u -p 5555

 

The EchoClient will randomly generate between 50 and 500 messages, and then terminate by sending the termination message.

 

 

4.     What to submit

 

  1. Your source code.
  2. A shell script that completely compiles (and links if the code is C or C++)  the program.  If you do not provide this script I will send your submission back to you as an incomplete submission.
  3. Answers to questions in section 5 below.

 

 5.  Questions:

 

a)       In the grading section above I specifically omitted TCP from the criteria about correct number of messages.  Why? (2 points)

b)       If you had to build a server application that sent a data stream to a client with little or no jitter, how would you do it?  (1 point)

c)       Give two examples of applications where UDP is a better choice for transport protocol than TCP  and EXPLAIN why. (2 points)

 

As always, You MUST be sure that your program complies, links and runs correctly on the NYU Solaris systems: this is where we will test.  Submissions that are incomplete or will not compile, link, or run according to your instructions will be returned to you and you will have to re-submit and accept an incomplete in the course and a loss of one half letter grade when you resubmit.  No resubmitted assignment will be accepted after December 20.