CSC 209H: Assignment 4

Weight: 10% of course grade.

Due date: 10:00 p.m. Thursday December 8


Introduction

In this assignment, you will be writing a simple client-server chat system. You will be writing two C programs, one server and one client, that implement a basic protocol allowing users to communicate.

Revised: the requirements to implement some commands have been removed. See the comments below in red.


chatserver

Your server will be called chatserver. It will listen on the specified port for client connections, maintain a list of currently connected users, handle requests from users, and pass messages between different users.

Once a client connects, your server will handle a sequence of commands sent by the client. A list of commands a client may send is below. Each command is terminated with a null '\0' character.

The following rules and limits apply to the above commands

Your server must service all connected clients fairly. If a client makes a request, it should not have to wait for another idle client to make a request before it is serviced. (That is, use the select function.)


chatclient

The second C program you will write is a client program that will interface with your server program via the protocol described above.

Your program should support being run in the following manner:

$ chatclient host [username]

host is the name or IP address of the server to connect to, and is required.
username is the name to be used for the connection. If username is not specified, the value of the environment variable USER should be used.

Your client program will connect to the server, introducing itself with the HELLO command, and reporting whether the connection is successful or denied. It will then present a list of users currently logged into the server, and process commands from the user.

The user may enter various requests, which the client will send as commands to the server. The format of these requests are somewhat inspired by IRC.

Each request will be a line of input read from stdin. If the message is long (for example, more than 60 characters), the client must break it up into multiple commands to be sent to the server. A blank line on input should be ignored (and not sent as a message).

Whenever the client receives a MSG from the server, it will print the message to stdout in the format:
<fromuser> message
where fromuser is the name of the user who sent the message.

Example

The following might be a sample execution of the program.

$ ./chatclient localhost me
Connected to 127.0.0.1 as me
janedoe
me
<janedoe> Anyone out there?
I'm here
<me> I'm here
/talk janedoe
how's the assignment going?
/done
<janedoe> We have an assignment to do?
<janedoe> I've got to go!
/msg janedoe Don't worry, it's pretty easy
janedoe is not logged in
/who
me
/quit

Hints, Tips and Clarifications


What to hand in

You will commit to the a4 directory of your CSC209 repository the following files:

You are strongly encouraged to take advantage of the version control system and commit your work frequently so that you can keep track of your progress. Please note that perfectly fine (and even recommended) that you keep any additional files related to this assignment (such as files and scripts used for testing) under version control. The markers will simply ignore such files.