Chat Client

Named pipes and multiplexed I/O with select()

In this project you are going to learn about two new topics, using pipes for interprocess communication and using multiplexed I/O to construct a single-threaded server application.

Unlike previous projects, I will not be providing you with code samples or lecture notes to use as a starting point. Your first job will be to do some reading in the textbook and some research online to get a basic understanding of these concepts.

A chat system

In this project you are going to implement a chat application. I will provide you with a chat client application and you will construct two server applications. The main server application will allow users to send in comments for the chat, and will distribute those comments to all the connected clients. A secondary server application will collect the most recent comments sent to the main server in a transcript. Clients can connect to the secondary server to download a list of the most recent comments in the chat.

Here is how the system will work:

  1. The client application will start by connecting to the secondary server. When the client connects, the secondary server will send back up to 20 of the most recent comments in the chat for the client to display. After sending those comments the secondary server will close the connection.
  2. The client application will display the recent comments for the user, and then connect to the primary server.
  3. Clients will send chat comments to the primary server, and the primary server will distribute comments to all of the clients and to the secondary server.
  4. When the secondary server starts up it will open a named pipe and start checking for input from that pipe.
  5. When the primary server starts up it will connect to the named pipe that goes to the secondary server.
  6. The primary server will operate in a loop. On each pass through the loop the primary server will use multiplexed I/O to see if any new clients have arrived or if any new comments have arrived from any of the connected clients. If a comment is available the server will send a copy of that comment to all connected clients, and then also put a copy of that comment in the pipe to the secondary server.

Hints and suggestions

Click the button at the top of the page to download an archive containing a NetBeans project for the client application. You will run the NetBeans application on your laptop, and it will connect to the server applications running in your container. The Java application assumes that the primary server is listening on port 8000 of localhost and the secondary server is listening on port 8001.

Since we need to run two server applications you will need to rebuild your container to expose two ports instead of just one. Run this command in a terminal to set up your new container:

docker run --name Chat -p 8000:8000 -p 8001:8001 -v "$(pwd)":/home/480 -it ubuntu /bin/bash

Remember that this command will map your current working directory to /home/480 in the container, so please be careful to cd to the correct directory before running this command.

Once you have set up the new Chat container, start it up and open a command prompt to it and run

apt update
apt upgrade
apt install build-essential gdb

Next, read the section on multiplexed I/O in chapter two of the textbook. You should also take a look at this example of a single-threaded server that uses multiplexed I/O to watch for input from multiple clients.

The textbook does not provide coverage of named pipes, so you will have to fall back on online resources. Here are a couple of reasonably good online tutorials on pipes and named pipes.