CIS 432/532 Introduction to Computer Networks
Winter 2001

Program #1: Simple TCP Socket Programming in Java and C
Due January 29th, 3:00 PM, online and in class

Overview

You will write both a Java and a C version of a simple TCP client/server program. For the Java program, you will modify the code discussed in Chapter 2 of the Kurose & Ross textbook. You will then write a C version of this program based on your reading of the Donahoo & Calvert socket programming guide.

Java Program

The Java client/server program is discussed in section 2.6.2 of the Kurose & Ross textbook. In this program, a client reads a string from standard input and sends this string to the server. The server capitalizes the string and returns it to the client, which prints it on standard output.

You should modify this code so that the server keeps the connection open with the client, and the client can type more than one line to the server. You should also modify the server so that it can do more than just capitalize a line. It should be able to capitalize, lowercase, and count the number of characters in the a line.

The format of a line that the client sends to the server is:

[Command]:[Rest of the Line]

Valid commands are:

  Command Server Action
  upper Change the line to be all uppercase letters and return the line to the client.
  lower Change the line to be all lowercase letters and return the line to the client.
  count Count the number of characters in the line and return this count to the client.
  close Return the line "OK" to the client and then close the socket.

Both the client and server should loop forever until the close command is entered by the user. The server quits after it reads the close command and sends "OK" to the client. The client quits after it receives "OK" from the server.

NOTE: You should write this code so that the client uses only one socket for its entire lifetime.

Here is an example of what the client should be able to do:

> java j_client -s ix -p 5232
%upper:Hello how are you?
HELLO HOW ARE YOU?
%lower:I'm feeling GOOD!
i'm feeling good!
%count:Lovely.
7
%close:
>

C Program

You should write a C or C++ version that operates identically to the Java version.

Command Line Arguments

Your Java executables must be called j_server and j_client. Your C executables must be called c_server and c_client.

For both Java and C, the server should take the following arguments:

  Argument Definition
  -p [port] Port number of the server.
  -d Print debugging information.

For both Java and C, the client should take the following arguments:

  Argument Definition
  -s [server] Machine name of the server (i.e. ix.cs.uoregon.edu).
  -p [port] Port number of the server.
  -d Print debugging information.

By passing these arguments on the command line, you can try running your server on different machines and ports. You can use the debugging flag to print out any helpful debugging information you want, but you should never print debugging lines if the flag is not specified on the command line.

Input and Output

Your server should not print anything to standard output. The only exception is debugging information, and this is printed only if the debugging flag is given on the command line.

Your client should print a "%" prompt for the user and should print any lines received from the server except for the "OK" line received in response to a close command. (If the user wants to capitalize or lowercase the string "OK" then of course the client should print it.) You can see an example of this behavior above. As with the server, the client should never print debugging information unless the debugging flag is given.

Compiling and Running

You must supply a script called compile that will compile your Java client and server. You must also supply a Makefile that will compile the C client and server when the user types make. The executables must have the names listed above.

Sample Code

You can find the Java code from the textbook, plus sample C code, in the class directory at /cs/classes/cis432/program1.

Grading

Your programs will be tested in two ways. First, your client and server will be tested with each other. They should operate as described in this assignment. Second, your client and server will be tested with a solution client and server. Your client should be able to talk to the solution server, and the solution client should be able to talk with your server.

If you wish to receive partial credit for a program that does not operate correctly, you must print out clear and concise debugging information when the debugging flag is given on the command line. I will use this information to determine how much of your program works and therefore how much partial credit you will receive. The more helpful and clear your debugging information is, the better your chances. You should apply this same standard to how you document your code.

Any program that does not compile or that crashes while running will receive a 0.

Turning in the Assignment

You must submit all your source code online. Do not submit any object code. Use the submission instructions for this program, which are available in the Schedule section of the class web page.

You must also print out and fill in the survey for this program. The survey is also available in the Schedule section of the class web page.