Program 5
Typically, the server in a client-server relationship has to be able to
handle multiple clients. An FTP, Telnet, mail, file or name server wouldn't
be of use if you had to take turns with a legion of unknown competing users.
This problem is handled by having the server create a child process to handle
each client. This is described in more detail in the
Unix Network Programming Manual .
For this assignment, your are going to create a server to handle multiple
clients as described below.
This is easiest done by building a server to handle a single client,
making sure that the part that handles the client is isolated from
everything else. Then expand it to a multiple client structure. It
is vital that you properly terminate the child processes, and that requires
that the child exit AND THAT THE PARENT PERFORM A WAIT SO THAT THE CHILD
PROCESS IS COMPLETELY REMOVED. This is described in the Unix
Network Programming Manual, but is often overlooked by beginners.
The server you create is going to do what Program 2 did in providing clients
with database lookup capability. There are no special modifications needed
for this type of service to multiple clients, since each is completely
independent of the other. This will not always be the case.
When creating your server, have it output data on every new client connection,
reporting the address of the client and the port being used. The getsockname
call applied to the socket returned by the accept statement can be used to
get this information.
Turn in a script of the output from the clients and servers along with the
source code.