MP 4 - Network Database Server
Due: 12/3/1999
For this assignment, you are to create a client/server socket program that will allow multiple clients to simultaneously connect to a simple database. When a client wishes to use the database, it will first make a connection request to the server. The server will then fork a child to communication with the client across the client's socket. The server child will perform the actual reading and writing to the file database. The file database must make use of read and write locks on individual records to allow/disallow simultaneous accesses to the database.
The server process must have the name of dbs, and the client process must have the name of dbc. The client process must take on optional command line argument. If no argument is given, it will assume the current machine contains the server socket. If an argument is given, it will assume that the argument is the name of the machine that contains the server socket.
The database will have ten records, numbered from 0 to 9. Each record will have two fields: a name field (of size 30 characters) and a phone number field (of size 20 characters). When accesses either field in the record, the entire record must be locked.
To use the database, the client will send a command across the client socket. The server child will retrieve this command and attempt to perform the desired action. If the action is successful, the server child will send either the resulting information across the client socket or a confirmation that the command was successfully performed to the client. If the action is unsuccessful, the server child will send a message stating the action was unable to be performed. The reasons for the unsuccessful action is because of conflicting locks set on the desired record(s). Your program is not to block the process, but simply to report the unsuccessful action.
The interactive commands that the client process must access are:
Set the name field to <name> at record <pos>. The <name> will start with the first non-white space character after <pos> and continue until the end of the line. If there are no non-white space characters after <pos>, the name is to be set to the null string. If there are more than 30 characters after the first non-white space character, truncate the name to the first 30 characters. This command must a write lock at record <pos> prior to the writing of the field. It must unlock the record after the writing of the field. If the write lock cannot be set, report an unsuccessful access to the record.
Set the phone number field to <phone number> at record <pos>. The <phone number> will start with the first non-white space character after <pos> and continue until the end of the line. If there are no non-white space characters after <pos>, the phone number is to be set to the null string. If there are more than 20 characters after the first non-white space character, truncate the phone number to the first 20 characters. This command must a write lock at record <pos> prior to the writing of the field. It must unlock the record after the writing of the field. If the write lock cannot be set, report an unsuccessful access to the record.
Retrieve the name field from record <pos>. This command must set a read lock at record <pos> prior to the access and unlock the record after the access. If the read lock cannot be set, report an unsuccessful access to the record.
Retrieve the phone number field from record <pos>. This command must set a read lock at record <pos> prior to the access and unlock the record after the access. If the read lock cannot be set, report an unsuccessful access to the record.
Retrieve both the name and phone number fields from record <pos>. This command must set a read lock at record <pos> prior to the access and unlock the record after the access. If the read lock cannot be set, report an unsuccessful access to the record.
Retrieve both the name and phone number fields from all records. This command must set a read lock at each record prior to the access of that record and unlock the record after the access. If the read lock cannot be set for a particular record, report an unsuccessful access to that record and continue with the access to the other rocords.
Set a read lock at record <pos>. If the read lock cannot be set, report an unsuccessful access to the record.
Set a write lock at record <pos>. If the write lock cannot be set, report an unsuccessful access to the record.
Unlock the record <pos>.
List all of the commands for this program with a short description on how to use each one.
Have the client process exit. This will cause the server child process to exit as well. The server process must properly clean up (i.e. wait() ) after the termination of its child (i.e. catch the SIGCHILD signal).
Once started, the server will remain running until it is killed by the SIGKILL signal. For 10 points extra credit, allow for graceful shutdown of the server. When the server receives a SIGTERM signal, before it shuts down it must:
For additional extra credit the assignment may be turned in early. If the assignment is turned in by Wednesday 11/24/99, you will get 20 points extra credit. If the assignment is turned in by Saturday 11/27/99, you will get 15 points extra credit (note, if the system goes down over the Thanksgiving Break there will be no extensions given to allow for this situation). If the assignment is turned in by Monday 11/29/99, you will get 10 points extra credit. If the assignment is turned in by Wednesday 12/1/99, you will get 5 points extra credit.
Your program is to be written in good programming style and should attempt to take advantage of C++ classes and the C++ Standard Template Library. All programs must be turned in electronically using the UNIX turnin command with the project name of mp4.