BUILDIND THE INTERNET

Socket Programming with TCP


This group exercise is taken in part from Jim Kurose's CMPSCI 453 course at UMASS.

In this group exercise, you'll write a client< that will use sockets to communicate with a server that you will also write. Once you are sure it is working, you will create a LAN with your group partner and test your client/server program. Here's what your client and server should do:

  1. The client program should first accept an integer between 1 and 100 from the keyboard, open a TCP socket to the server and send a message containing:
    1. a string containing your name (e.g., “Client of Alan Turing”)
    2. and the entered integer value and then wait for the sever to reply.
  2. The server will create a string containing its name (e.g., “Server of Grace Hopper) and then begin accepting connections from clients. On receipt of a client message, your server should:
    1. print (display) the client's name (extracted from the received message) and the server's name
    2. pick an integer between 1 and 100 (it's fine for the server to use the same number all the time) and display the client's number, its number, and the sum of those numbers
    3. send its name string and the server-chosen integer value back to the client
    4. and if your server receives an integer value that is out of range, it should terminate after releasing any created sockets. You can use this to shut down your server.
  3. The client should read the message sent by the server and display its name, the server's name, its integer value, and the server's integer value, and then compute the sum. The client then terminates after releasing any created sockets. As an aside (and as a check that you are doing things correctly, you should make sure for yourself that the values and the sums are correct!)

The last part of the group exercise is to build a LAN (Local Area Network) with your teammate and get your client to interact with their server and/or vice versa. Make sure you capture the output from the client or the server, since you'll be printing out the name of your teammate's client or server with whom your client or server is interacting.



Resources

Here are a couple of important resources:

  • Java Socket Programming: Java version of the client/server code for TCP sockets
  • Python version: your class book (section 2.7) has the code for python implementation of client/server code for TCP sockets.

Here are a few tips/thoughts to help you with the exercise:

  • You must chose a server port number greater than 1023 (to be safe, choose a server port number larger than 5000). If you want to explicitly choose you client-side port, also choose a number larger than 5000.
  • You need to know your machine's IP address, when one process connects to another (that's the IP address you will choose when configuring your LAN. You can also use the UNIX nslookup command . On Windows, see the ipconfig utility. On a Mac, you can run the terminal program and use the ifconfig commend (just type in ifconfig or ifconfig | grep "inet ").
  • Make sure you close every socket that you use in your program. If you abort your program, the socket may still hang around and the next time you try and bind a new socket to the port ID you previously used (but never closed), you may get an error. Also, please be aware that port ID's, when bound to sockets, are system-wide values and thus other students (connected to the LAN) may be using the port number you are trying to use.



Programming Part

Programming the assignment in JAVA

You can use JAVA if you prefer. Here is the JAVA-based socket section of the text that is from the 5th edition: Java Socket Programming. Java encapsulates the concept of a client-side connection-oriented (TCP) socket with the class, Socket. Details about the socket class, and the other classes noted below, can be found at JAVA Sockets.

Java encapsulates the concept of a server-side connection-oriented socket with the class, ServerSocket. You'll need to use the accept() and close(0) methods of this class, which are also document at this URL.

If you're interested in a quick Java tutorial targeted specifically at socket programming, check out is at Sun's socket tutorial.

Programming the assignment in Python

The 6th edition of the textbook (and what we've discussed in class) uses sockets in Python. A Python socket tutorial can be found here http://docs.python.org/howto/sockets.html.



What to Submit

When you are interacting with your teammate, open WireShark and capture some TCP packets to study their content, making sure you can "see" the messages that are being send, the ports and addresses are correct, and so on.

Prepare a 2 to 3 pages long report (one per group) addressing the group experience building a LAN network and programming TCP sockets to communicate in a client/server model. Make sure to append your code (one for the client and one for the server), you WireShark capture showing the TCP connections containing the data being shared among client and server.



Evaluation

Your report will be graded on the following scale:

  • Exceeds Expectations 5pts.
  • Meets Expectations 4pts. (A)
  • Near Expectations 3pts. (B)
  • Below Expectations 2pts. (C)
  • Poor Effort 1pt. (D)
  • Not Done 0pts. (F)