Skip to content

jpfsh/concurrency-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zotdonate: a small-scale charity-donation server

Two versions:

  1. 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.
  2. The second version utilizes a readers-writer model (reader preference).
  • Note: corresponding client programs are pre-provided binaries (in ./bin/) rather than programmed ones.

Testing everything for thread-safe code:

./test.sh
  • (preferably run test.sh in multiple terminal panes/sessions at once to stress-test concurrency and such)

Part 1 - Multi-threaded Server

alt_text

./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.

Part 2 - Readers-Writer Server

alt_text

./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 "<fd> DONATE <charity> <amount>\n" to the donation log.

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 "<fd> CINFO <charity>\n" to the donation log.

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 "<fd> TOP\n" to the donation log.

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 "<fd> STATS <charity_high>:<amount_high> <charity_low>:<amount_low>\n" to the donation log.

Server
0xFF ERROR Error occurred due to an invalid message

Once the response is set to the client, print "<fd> ERROR\n" to the donation log.

Server

Part 1 - Multi-threaded Server - Client

./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

Part 2 - Readers-Writer Server - Client

./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

Full list of Client Commands

Command(s) Description Client Version
/help

/h

Lists available commands to run All
/donate charity_id amount

/d 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: DONATE

client \ Wclient
/cinfo charity_id

/c

Sends a request to the server for all information about a specific charity. Results are displayed on the terminal.

msgtype: CINFO

client

Rclient

/top

/t

Sends a request to the server for the top 3 total client donations. Results are displayed on the terminal. \ msgtype: TOP client

Rclient

/stats

/s

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

/quit

/q

Sends a request to the server to logout the user.

msgtype: LOGOUT

All

About

thread-safe charity-donation server using the Berkeley sockets API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published