Threaded Server
Description
Write two programs that communicate via sockets in a client-server relationship.
General Specifications
The default make target should create both executables.
Your programs must all be properly modular and documented appropriately.
The allowable languages for this assignment are: C, C++, OCaml (Unix module), Go (sys/unix package), Rust (nix:unistd crate).
server Specifications
The name of the compiled program must be
server.The input to the program must be in the form of command line arguments as follows:
-h(by itself with no other arguments) print the usage instructions-p <string>(required) the port number-m <string>(required) the name of the pokemon binary file-t <string>(required) the name of the trainer file-l <string>(required) the name of the log file
Note that the command line arguments must be able to be entered in any arbitrary order.
The main steps for the server process should roughly be:
- Set up and open the binary data files. If the trainer file does not exist, create it. If the log file does not exist, create it.
- Open a socket.
- When a client connects, spawn a thread to handle the client concurrently.
- For each client request, append a timestamp, the IP address, the port number, and the request command as a single line to the log file.
- When a SIGINT signal is received, gracefully shut down the program (handle a currently connected client, close the named pipe, etc.)
The thread should handle client requests until the client is done (or the server is interrupted.) The types of client requests are listed in the client section.
Note when processing the binary files, only one record may be in memory at a time. This may effect the implementation for some of the client requests, for example, the
get trainerrequest must return all trainers in the response, but the server may only have one record in memory at a time.Note that the both the trainer binary file and the log file can be read and written by multiple clients concurrently.
client Specifications
The name of the compiled program must be
client.The input to the program must be in the form of command line arguments as follows:
-h <string>(required) host-p <string>(required) port
Note that the command line arguments must be able to be entered in any arbitrary order.
The client must be a read-eval-print loop (REPL) application, that is, is a simple interactive application that takes single user inputs, executes them, and returns the result to the user. These are the commands that the client must implement:
exit– quit the application (indicate this to the server)get pokemon <id>– request data for a pokemon with the “number” equal to the<id>argument and display it in a well-labeled format if the “number” exists. The server responds with the appropriate data on success or indicates that the record does not exist.get trainer– request all (valid) trainer data and display it in a well-labeled format. The server responds with the appropriate data.get trainer <id>– get the data for the trainer with the ID equal to the<id>argument and display it in a well-labeled format if the<id>is valid. The server responds with the appropriate data on success or indicates that the record does not exist.post trainer <name> <pokemon id 1> [<pokemon id> ...]– send data for a trainer that includes the trainer’s name and at least one pokemon (at most six) and send the data to the server. On success, the server responds with the ID of the newly created trainer data. Otherwise, the server responds with an indication of failure.put trainer <id> <pokemon id 1> [<pokemon id> ...]– send data for a trainer that includes the trainer’s id and at least one pokemon (at most six) and send the data to the server. On success, the server indicates that the data was successfully updated. Otherwise, the server responds with an indication of failure.delete trainer <id>– delete the record with the corresponding<id>On success, the server indicates that the data was successfully updated.get log <n>– get the lastnentries from the log file. Ifnis greater than the total number of entries, then get all existing entries in the log file.
Turning in the Assignment
For this assignment, you must turn in a zip file of a directory
named project6 containing the following files:
- README (containing design decisions and a description of the protocol)
- Makefile
- Source code
- Pokemon binary file
good.txttest file (tests all commands in the successful cases)bad.txttest file (tests all commands in the failing cases)
The test files must be able to run with file redirection like so:
./client -h <host> -p <port> < test.txt
Submit the zip file to the appropriate folder on D2L.