CIS307: Homework 5: Communicating through Sockets

This homework is given April 9 and it is due April 19 by 5pm.

It is a continuation of homeworks 3 and 4. Now communication between clients and server is not taking place in a single computer using pipes or accessing a shared memory. It is taking place across networks using sockets.

Support material on the use of sockets is provided in class, in the Unix notes, and by looking at the code available with the networking book by Stevens. Here are a trivial client and server, here are another client and server, and here are one more client and server.

Now the STORE_MANAGER is a server program running on a computer, say Snowhite.cis.temple.edu. It is started from the Unix shell and it is called without command line parameters. It obtains a port from the system and prints out its id. It creates a datagram socket, and it binds it to this port. Then it waits to receive messages from the clients. When it receives a message from a client, it creates a thread and gives the request to it together with information on the requestor (the thread needs this information in order to send information back to the requesting client). The thread carries out the request and sends back a reply on the same socket. It then terminates. In the meanwhile STORE_MANAGER waits for and services the next message which it handles in a similar way. [Implement the STORE_MANAGER first without using threads, i.e. as a program that handles requests sequentially. Only after it works re-implement it using threads.]

A client program RAND_PROC is also started from the Unix shell on the same or on a different computer. It is given three command line parameters:

The client program, RAND_PROC, will use a datagram socket to communicate with the server. RAND_PROC will send messages to the server (as identified by the IP and by the port specified in the command line) through this socket and will retrieve messages from this same socket.

Both the client and the server will use timeouts when waiting for messages. At the timeout they print a warning message and then they go back to waiting.

The RAND_PROC program consists of two processes, hmw_main and a single rand_proc process (these proceses are similar to those used in homework 3). Hmw_main forks rand_proc and communicates with it with signals as in homework 3. Rand_proc will send Read and Update requests to the store manager. Hmw_main can send to the store manager a Store_Balance request which will return the sum of all the balances currently in the Store. Store_Balance can be executed concurrently with Read operations but in mutual exclusion with Write operations. All three operations are slow, they take about a second each (you will have to use an appropriate sleep statement within the operation to represent the time elapsed from the beginning to the end of the operation).

For synchronization and mutual exclusion you can use mutexes and condition variables, but you are not allowed to use file locks as you did in Homework 4.

RAND_PROC and STORE_MANAGER will exchange messages and log in the same way as they did in homework 3 (but of course now they use sockets, not pipes).
The programs should keep operating correctly even if you launch a number of copies of RAND_PROC, perhaps on different computers.

RAND_PROC will respond to signal 1 from hmw_main by printing statistics as in homework 3. It will respond to signal 15 by terminating gracefully. STORE_MANAGER will terminate when we send to it from the unix shell the appropriate kill signal.

ingargiola@cis.temple.edu