UMD Logo

Project 1 - CMSC 417, Spring 2000 Section 0101 and Section 0201

Due: Wednesday February 9, 2000 (before midnight)
The term project will require heavy use of the Berkeley UNIX networking facilities (often called the BSD Socket Interface). The user interface to these facilities is rather complicated and confusing, so you are asked to do a simple exercise to gain familiarity with the interface before you have to start using it for your project. For this assignment you will use Internet-domain sockets and TCP (Transmission Control Protocol) for communication between a client and server, possibly running on different machines.

You should use the UNIX cluster systems and obtain your account information (user ID and password) from the TA.

The Assignment
You will write a client program which will communicate with the server program provided by us. You are also given a ``sketch'' of the client program; all you have to do is fill in the communication parts.

The server, SERVER_HOSTNAME, creates a socket in the Internet domain bound to port SERVER_PORT (both constants are defined in the .h file provided for you), receives messages from it, acts on the messages, and returns the results to the requester. For this simple exercise, there are only three types of messages: HELLO and BYE messages from a client to the server and an ACK message from the server to a client. Each message is a simple character string which consists of several fields, and which must be terminated by a new-line character, '\n'. All fields of a message must be separated by exactly one blank space, ' '. The number of fields varies with the message type.

Each HELLO message has five fields: (1) a version field (must be set to "PROJ1" for Project 1), (2) a uid field (this is your AITs login id), (3) a firstname field (this is your first name), (4) a lastname field (this is your last name), and (5) a type field, "HELLO". A sample HELLO message (in C/C++ string format) is as follows:

	"PROJ1 lg41799 John Henderson HELLO\n"
(Please note that '\n' means a new-line character, not a two-character string). A client sends a HELLO message to the server, waits for the reply, responds with another message, and then prints the uid, the firstname, and the lastname (which were sent in the HELLO message) along with a cookie received in the reply (as explained below).

When the server receives a HELLO message (type field is set to HELLO), it will construct a response message and send it back to the client. The response message has three fields: (1) a version field ("PROJ1"), (2) a cookie field, and (3) a type field, "ACK". A cookie is a randomly generated number which is returned by the server to a client. You must use the same number (i.e., cookie) to send a BYE message to the server (as explained below) to complete the communication. The following is a sample C/C++ string (message) returned by the server:

	"PROJ1 1234567 ACK\n"

When a client receives an ACK message (type field is set to ACK), it will construct a BYE message and send it back to the server. A BYE message has three fields: (1) a version field ("PROJ"), (2) a cookie field, and (3) a type field, "BYE". In this case, the cookie must be identical to the one received from the server in the corresponding ACK message. (The server will generate different cookies for clients on receipt of different HELLO messages.) A BYE message looks as follows:

	"PROJ1 1234567 BYE\n"

Please note that, there are no blank spaces inside a field.

The command line syntax for the client is given below. The client program takes several command-line arguments, corresponding to the uid, firstname, and lastname fields of the HELLO message (as described above). The hostname and port specifications are optional. If included, this must override the default definition of SERVER_HOSTNAME and SERVER_PORT. The optional port is appended to the optional hostname and separated by a colon (as in URLs).

client [-h <hostname>:<port>] -u <uid> -f <firstname> -l <lastname>
You will be doing the term project in teams. However, for this assignment, you must work individually, so that each of you becomes familiar with the socket interface. Prior to the submission deadline, you must use your client program to communicate with our server and obtain a cookie. You must then submit (via the submit program) your client program and the cookie. The cookie must be included in the README file. See Submission Guidelines for details. Note that, you can test your client code with our server as many times as you like, but you must submit the cookie which you receive on your last communication with the server.

You will be building on these programs for subsequent stages of the term project, so it is in your own best interest to make them maintainable.

The client program will not be long (probably about 100-200 lines including comments), but it may be difficult to write, and it will certainly be difficult to debug. First read Berkeley UNIX System Calls and Interprocess Communication by Lawrence Besaw very carefully. This document will have some information which you will not need to know for this assignment (e.g. UNIX domain sockets and the UDP protocol). Pay particular attention to the program example at the end. Figure out which system calls will be needed by your your client program and read the corresponding man pages. You might also find "Internetworking with TCP/IP, Vol III", by Comer and Stevens, Prentice Hall (Chaps 5 and 6) as well as "UNIX Network Programming" by W. Richard Stevens, Prentice Hall (Chap 6) useful. The Comer and Stevens book should be in the Engineering Library.

You should use gcc as your compiler, rather than cc. Gcc supports prototypes and other ANSI extensions, which you should use in your programs. The option -Wall turns on most of the useful gcc warnings. Compiling with this option will find many simple mistakes in your programs. You should try to get your programs to compile with as few warnings as possible. Part of your grade will be based on how warning-free your program compiles. You may also add options -ansi. This will make the compiler reject non-ANSI programs. On many platforms you also need to link the network and socket libraries to your program. You should use the gmake program to compile your program. Make(1) is a program that reads a file (Makefile) that describes how to compile your program.

Use netstat(1) to see what sockets have been created by your program (you may have to put it in the background; once a program terminates, the sockets it created go away).

Clean up! Use ps(1) to see what processes you have left lying around, and use kill(1) to get rid of them.

Be sure to check the Project Notes and the Submission Guidelines listed on the class Web page for other requirements.

Have fun and good luck!

[Last updated Tue Feb 1 2000]    [Please see copyright regarding copying.]