CS 3733 Operating Systems, Spring 2000 Assignment 6


Part 1 Due Friday, April 21
Part 2 Due Monday, May 1


In this assignment you will write a media server capable of serving several channels of various kinds of media and a client capable of receiving audio and text files from the server.

The server:
The server will be started with a command line of the following form:

   mediaserver port channels filename1 filename2 ... filenamek
The first argument is an integer representing the port number for listening for connections.
The second argument is an integer representing the number of simultaneous channels of media to be broadcast.
The rest of the parameters are the names of media files. The number of media files can be any integer greater than 0.

The server will keep track of the total number of client connections open and not serve files if this value is equal to the channels parameter.

The server will accept two types of connections based on the first message it receives from the client.

If the first message is exactly 4 bytes and consists of the word "menu", it will send back a menu message and close the connection.

A menu message will be a message which gives a menu of numbered available options. It will include a list of the media programs available which consists of the names of the files from the command line. For example, if I wrote the server and it were started with the command line:

   mediaserver 12345 5 program1.au program2.au instructions.txt
and there were two audio channels currently being served, the menu might look like this:
   Media server written by Steven Robbins has 3 channels available out of 5.
   Enter one of the following program numbers:

   1. program1.au
   2. program2.au
   3. instructions.txt
The exact form the this message is not critical, but it should contain your name, the number of available channels, and the list of files. The menu messages do not count as using a channel.

If the first message from the client is anything other than the word "menu", it will be interpreted as a sequence of digits representing one of the program numbers. In this case the server responds by sending a single byte of data which either indicates that an error has occurred, or the type of file requested.

Error and type codes are defined in mediaserver.h which is available in usr/local/courses/cs3733/spring2000/assign6. If an invalid command is received, a MEDIA_COMMAND_ERROR is returned. If the server cannot open the file, a MEDIA_FILE_OPEN_ERROR is returned. If no channels are available, a MEDIA_NO_CHANNELS is returned.

If an error code is sent, the connection is closed.

The only media types supported for this project are audio and text. Audio file names end with .au and text file names end with .txt. After sending the type, the entire file is sent to the client and the connection is closed.

The client:
The client will be started with a command line in the following form:

   mediaclient port hostname
The first argument is a port number and the second is the name if the host machine.

The client starts by displaying a message to standard output giving the name of the programmer. The client will start by attempting to make a connection to the server and sending it a "menu" message and displaying the response.

The client then waits for input from the user (standard input), makes a second connection request to the server, and sends the user input to the server.

If this is successful, the client displays an appropriate message and handles the data received. If the data is of type text. it it just sent to standard output. If the data is of type audio, it is assumed to be u-law 8-bit audio data with a 32-byte header. The audio device is opened and all of the data after the header is sent to the audio device. It continues doing this until the connection is closed by the server or an error occurs.

When the communication is complete, the client displays an appropriate message and exits.

For this assignment, you will need to use port numbers which do not conflict with those used by other students. Each student has been assigned 10 port numbers, although you will only need one of them. The port assignments are given here.

Part 1
Write the client program. You can test it with the server which is running on vip.cs.utsa.edu and listening on port 10100. One of the text entries is called instructions. Read these instructions for additional information.

There may be times when the server is not running on vip. If you find that the server is not running, send me email and I will start it up again.

For this part, just hand in your source code. Use the cover sheet called cover61.ps in /usr/local/courses/cs3733/spring2000.

A copy of the UICI code along with the simple client and server from the book are available in /usr/local/courses/cs3733/uici_source. This contains a version of UICI in which the server will not hold onto the port number after it terminates.

Part 2
Write the server. This is the harder part. The server should fork a child process to send the media files to the client. The server needs to keep track of the number of open channels. Figure out how to do this. Two possibilities are to use signals or pipes to allow the children to communicate with the parent. You may find another method if you like.

Make sure that your server handles zombie child processes.

For this part, hand in your source code for both the client and the server. Use the cover sheet called cover62.ps in /usr/local/courses/cs3733/spring2000. You may want to print out the cover sheet early to see what additional information in required.

Optional