Data Communications and Networks



Assignment 4 -  Socket Programming (15 points)

Due Date:  Sunday November 23, 2003 before 11:59  PM


Revision 1:  November 5,   2003   initial posting.

Revision 2:  November 8,   2003   correct due date: should be Sunday., November 23

Revision 3:  November 12, 2003   Add notes: use float, exclude termination message in stats, add test program.

Revision 4:  November 13, 2003   Floating point, plagiarism, library use

Revision 5:  November 13, 2003   Remove reference to rate as input to server, add link to Comer C code

Revision 6:  November 16, 2003   Clarify termination condition (sec. 2.2)


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 min, 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.  After you develop an average of 1000 samples, you may simply re-compute the average as if every subsequent sample was your 1001th sample:


Sn = ((n-1)*Sn-1 + Ln)/n            if n £ 1000


Sn = ((1000)*Sn-1 + Ln)/1001      if n > 1000


NOTES: You should use a floating point data type for S 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'.




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 (lamda) in milliseconds.

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

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



2.3.   Use of Libraries/Packages.



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

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


The code from Comer is here.




3.     Evaluation


This assignment is worth 15 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:        10 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


We 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



As always,. You MUST be sure that your program 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 the standard late penalty.


4.     What to submit


  1. Your source code.
  2. Instructions as how to compile (and link, if required) your program.
  3. Answer this question:

In the grading section above I specifically omitted TCP from the criteria about correct number of messages.  Why?  A correct answer will add 1 point (a bonus point) to your total.