CIS 432/532 Introduction to Computer Networks
Fall 2001

Program #2: Chat Application, Part II
Due 5th December online by 10am

Overview

In this assignment, you will modify your chat application so that messages can be received by the client and server in any size and number of buffers. The client and server for this assignment should not have any limitation on the length of messages sent between client and server, nor the amount of data the user can input in a single message.

Details

In the first chat application, we made the assumption that a server sends each message in a single buffer using send(). We also assumed that the receiver could receive the entire message in a single buffer with a single call to recv():

This assumption forces us to declare a maximum buffer size (the solution uses 1024) and assume that all messages are shorter than this buffer size. In addition, our application breaks if any message gets fragmented or buffered counter to our assumption.

In this assignment we will correct this poor assumption. When there is activity on a socket, both the client and server should make a call to recv() and then examine the contents of the received buffer, looking for an entire message. Since we mark the end of each message with a null character, it is easy to determine the boundary between messages. If the buffer contains a message, it is interpreted according to our previously-defined chat specification. The remainder of the buffer is then examined for additional messages, as the buffer may contain more than one. If at any time scanning the buffer, the end of the buffer is reached without reaching the end of a message, then this partial message must be saved and processed later when the rest of the message arrives.

For example, a single message might be split over two calls to recv():

Other messages could also be present in the buffer:

For this assignment, you will modify either your own client and server or the solution client and server. I will make the source code for the solution available online. You will mostly need to modify the recv() behavior of the client and server. However, you may also need to modify the send() calls so that they do not make any assumptions regarding message length. The same for reading input from the user. There should be no limitations on the size of a message sent between client and server.

Otherwise, all client and server behavior is as specified in the previous assignment. Each message ends with a null character.

Error Checking and Debugging

You should check for errors resulting from system calls. If a system error occurs, use the perror() interface to print out its corresponding code and then immediately exit the program. You must use the debugging flag to print out any debugging comments. This way you can turn off the extra comments via the command line.

Compiling and Running

You must supply a Makefile that will compile your C code. Your server executable must be called chat-server and your client executable must be called chat.

Grading

Your program will be tested by running the chat program to be sure it works as specified. In particular, we will use a client and server that deliberately split messages into multiple send() buffers, forcing you to read the input with multiple calls to recv(). We will expect that the client and server operate as specified in the previous assignment.

Any program that does not compile will receive a 0.

Turning in the Assignment

You must submit all your source code and documentation 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. Turn this in to my office on the due date (or put it under my door).