Two versions:
- A multi-threaded, charity/donation server. The first version handles each of the client (donor) with a thread. All threads interact with the shared data structures.
- The second version utilizes a readers-writer model (reader preference).
- Note: corresponding client programs are pre-provided binaries (in ./bin/) rather than programmed ones.
./test.sh
- (preferably run test.sh in multiple terminal panes/sessions at once to stress-test concurrency and such)
./bin/ZotDonate_MTserver [-h] PORT_NUMBER LOG_FILENAME
-h Displays this help menu and returns EXIT_SUCCESS
PORT_NUMBER Port number to listen on
LOG_FILENAME File to output server actions into. Create/overwrite, if exists
Example:
$ ./bin/ZotDonate_MTserver 3200 4000 log. txt 2> err. txt
Listening for readers on port 3200.
Listening for writers on port 4000.
./bin/ZotDonate_RWserver [-h] R_PORT_NUMBER W_PORT_NUMBER LOG_FILENAME
-h Displays this help menu and returns EXIT_SUCCESS
R_PORT_NUMBER Port number to listen on for reader (observer) clients
W_PORT_NUMBER Port number to listen on for writer (donor) clients
LOG_FILENAME File to output server actions into. Create/overwrite, if exists
msgtype
|
Name | Description | Sent By |
0x00
|
DONATE
|
Donate the specified amount to the specified charity based on msgdata donation information. Updates to all fields of the charity on the server are performed based on the donation. Add the donation amount to a local total for the client (for maxDonations).
|
Client |
Upon success, the client thread replies with the same message received.
Once the response is set to the client, print |
Server | ||
0x01
|
CINFO
|
Request for info about the charity specified in the msgdata donation charity field, other fields are ignored
|
Client |
Client thread replies with info in msgdata charityInfo
Once the response is set to the client, print |
Server | ||
0x02
|
TOP
|
Request for 3 largest total donations made by any client. msgdata is ignored.
|
Client |
Client thread replies with data in msgdata maxDonations fields
Once the response is set to the client, print |
Server | ||
0x03
|
LOGOUT
|
Upon receipt, the server terminates the client's socket connection. Print "<fd> LOGOUT\n" to the donation log. \
If necessary, update to top 3 maxDonations .
|
Client |
0x04
|
STATS
|
Request for information about the charity with the largest and the smallest donation totals. msgdata is ignored.
|
Client |
Thread replies with data in msgdata stats fields
Once the response is set to the client, print |
Server | ||
0xFF
|
ERROR
|
Error occurred due to an invalid message
Once the response is set to the client, print |
Server |
./bin/ZotDonate_client [-h] SERVER_ADDR SERVER_PORT
-h Displays this help menu and returns EXIT_SUCCESS
SERVER_ADDR The IP address of the server to connect to
SERVER_PORT The port to connect to
./bin/ZotDonate_Wclient [-h] SERVER_ADDR SERVER_PORT
-h Displays this help menu and returns EXIT_SUCCESS
SERVER_ADDR The IP address of the server to connect to
SERVER_PORT The port to connect to
./bin/ZotDonate_Rclient [-h] SERVER_ADDR SERVER_PORT
-h Displays this help menu and returns EXIT_SUCCESS
SERVER_ADDR The IP address of the server to connect to
SERVER_PORT The port to connect to
Command(s) | Description | Client Version |
/help
|
Lists available commands to run | All
|
/donate charity_id amount
|
Sends a request to the server to donate to the specified charity for the specified amount. Both charity_id and amount must be integer values.
msgtype: |
client \
Wclient
|
/cinfo charity_id
|
Sends a request to the server for all information about a specific charity. Results are displayed on the terminal.
msgtype: |
client
|
/top
|
Sends a request to the server for the top 3 total client donations. Results are displayed on the terminal. \
msgtype: TOP
|
client
|
/stats
|
Sends a request to the server for the charity with the highest and lowest donation amounts. Results are displayed on the terminal.
msgtype: STATS |
Rclient
|
/logout
|
Sends a request to the server to logout the user.
msgtype: |
All
|