In this assignment you will rewrite the programs from Assignment 3 so that they communicate over a network. Use the port numbers that were assigned to you for recitation number 9.
Part 0:
If you haven't already done so, finish Parts 8 and 9 of assignment 3.
Write an explanation of what you had to fix, how you tested
the program and what results you got.
Part 1:
In this part you will write a network client called
program_network_client.
Start with one of the
client network programs from Chapter 18 of USP. The description below
is very similar to that of program_client of Part 8 of
Assignment 3. The program takes two command
line arguments, a host name and a port number.
Part 2:
Write a main program called program_network_server that takes
two command line arguments: a filename and a port number.
The first argument will be referred to as infile.
This program will be similar to the program_server from Assignment 3,
but it will use a network connection rather than named pipes.
This should be a parallel server. It should fork a child process to handle
the connection.
Note: You should only have to read in the infile once, no matter how many requests are mad from clients.
Part 3: (extra credit)
Put the code for this part of the assignment in a part3 subdirectory.
Rewrite the server program of part 2 to use threads rather than child processes.
Keep track of the number of requests for each program and display this
in a message containing when a SIGUSR1 signal is
received by the server. Have the server display its process ID when it starts
so that you can send it a signal.
Make sure you understand where synchronization is necessary and be sure to use only async-signal safe functions inside any signal handler. Make sure that the other parts of the program work correctly in the presence of signals.
Write an explanation of how you tested the program and what results you got.
Part 4: (extra credit)
Only attempt this is you have Part 3 working correctly.
Put the code for this part of the assignment in a part4 subdirectory.
Rewrite the server from Part 3 so that instead of handling signals,
it sends a message giving the number of requests for each program to a
remote host that makes a connection on the port number which is one greater
than the command line argument. The message that is sent should be
self-explanatory and suitable for printing without modification.
Do this with a separate thread. Be careful about synchronization.
You can test this with your client from Part 1 and the client2 program from USP. Write an explanation of how you tested the program and what results you got.
Handing in your program (modified):
Use this cover sheet. Consecutively number all of
the other pages you turn in. Each page that contains your work should have
a number on it.
We will be meeting in the Sun lab during the regularly scheduled class time on Tuesday, April 27.
If your client and server are not working well enough to be tested in the lab, just hand in your assignment to me during the lab time. Be sure that you have filled in in the bottom of the cover sheet explaining exactly what progress you have made on this assignment.
If you think your programs are working correctly, you must demonstrate them to me in the lab. Create two fresh directories, one containing only the client executable and one containing only the server executable. Open a terminal window for each directory.
In the directory containing your server, execute the following command:
/home/srobbins/assign5/makelinks
This will make 4 symbolic links in your directory to files that will be used
by your server. Be prepared to start your server using program_file
as the first command line argument.
Find someone else in the class who is sitting at a nearby machine. Agree on port numbers to use. You will each demonstrate your client with the other person's server. You will be given the input files to be used at the time the programs are tested.
If you have done the extra credit also do the following: