CSCI 3500: Lab 5

chat - Network Chat Client


In this lab, you will:

  1. Write a chat server that manages multiple concurrent connections
  2. Write a chat client
  3. Perform asynchronous message passing between arbitrary numbers of clients
  4. Perform concurrent, nonblocking I/O

Parameters

This is a group assignment.


Usage:

server <IP address> <port number>
client <IP address> <port number>

Description

The goal of this assignment is to write a networked chat server and client. Multiple users will connect concurrently to a single server process via individual chat clients. The client program will send messages from users to the server, and will print messages from the server to the user's terminal screen. The server will keep track of connected clients, and when it recieves a message from any client it will pass that message along to all other connected clients. Each user will also have a name that is used to identify their statements.

Each user, when they first connect, should get a default name consisting of the string "User" followed by a unique set of digits. When a user connects to the server any other connected users should recieve a message stating "<user name> has connected".

Additionally, the client will support two special commands name and quit.

name command: When the client enters the phrase "name" followed by a space and at least one character, everything after the space will become the user's name. The system will then send this name in front of any subsequent chat messages. If the user specifies another name their current name is replaced. Lastly, when any user changes their name then all other users should recieve the message "<old name> has changed their name to <new name>"

quit command: When the client enters the phrase "quit" the client program will terminate. All other connected users should recieve the message "<user name> has quit".

Messages should always be printed to all terminals in less than a second, regardless of the current state of the system. (This means that your client should be able to display text even while waiting for input, and your server should be able to respond to an incoming request by any client at any time.)

If a client suddenly finds its socket to be closed then it should quit and print a message saying the server shut down unexpectedly. If the server finds a socket unable to be used it should print the same message as though the user quit normally.

Hints

Useful man pages

socket(2)
bind(2)
listen(2)
accept(2)
accept4(2)
connect(2)
shutdown(2)
shutdown(2)
ip(7)
pthread_create(3) read(2)
write(2)
snprintf(2)

Questions

  1. There are no exercises for this lab. Please mark your group clearly in your client code, your server code, and in your submission email.


Submission

Create a .tgz archive of your lab directory and email it to dferry_submit@slu.edu. Your submission must contain a file malloc.c which contains definitions for malloc, free, realloc, calloc but has no main() and with all output (cout, printf) removed.

The simple syntax for creating a .tgz archive is as follows:

tar -zvcf new_archive.tgz lab_directory

The syntax for unpacking a .tgz archive is:

tar -zvxf archive.tgz

Note that your archive must not include any binary executable files, meaning any compiled programs or intermediate build objects (.o files, for example). This will cause your email to be rejected by most services.