IPC using message queue: A server-client game. Github Link
This project implements IPC using message queue to simulate a server-client game.
-
We have a set of
k clients(k taken as input from the user) and one single server. -
The server is responsible to create and maintain the message queues.
-
The game consists of several rounds of server-client communications using message queues.
-
At the beginning of each round, the server accepts two integers
MINandMAXfrom the user, which it sends to all the clients using the message queue. -
Each client
jrandomly generates a guessed token (an integer) within the range[MIN:MAX]and sends that to the server, denoted by$R_j$ . -
Now, the server also generates a token, say
G(which is also an integer) in the range[MIN:MAX], independently (which is not shared with the clients). -
On receiving
$R_j$ , from all the clients, the server computes:$$δ = \frac{|R_j−G|}{∑(R_j−G)} , ∀j ∈ [0,1,2,...,k-1]$$ -
Among all the clients, the client scoring the smallest
δwins the round and gets a score of5. -
The first client crossing the total score 50 over multiple rounds is declared as the champion, which in turn ends the game.
gcccompiler to run C program.unixbased OS/Environment
cdto this directory and just run therun.shbash script using./run.sh- Enter the number of clients,
k, that should play this game. - For each subsequent round give space separated input of
MIN MAX, the range of values to be guessed for the round.
- For each round, the clients send their guessed token to server. The server also guesses a number in the same range.
- The winner of the round is calculated as per the above given rules.
- After each round, the stats of the game is printed which consists of token sent by each client for this round and total score of each client after this round.
- The game ends if anyone of the clients touches
50points mark.
k message queuesare created for the communication ofk server-client pairs.- Specific message type convention is followed for each queue, otherwise it may be possible that server sends a message to the queue and then receives the same message from the queue under the assumption that the message was sent by the client.
- To overcome above situation, by convention, the server always sends messages with
msg_type = 1to the queue and always receives messages withmsg_type = 2from the queue. Similarily, a client always sends messages withmsg_type = 2and receives messages withmsg_type = 1. - The value of k entered by the user must be positive i.e.
k>0. - The value of
MIN MAXentered for each round must satistfy:0 < MIN < MAX. - When the game ends, each client is sent an unusual
MINvalue to the client at the start of next round. This passes the message to the clients that the game has ended. If,MIN = - x, where x >= 0is sent by the server, it signifies that client withprocess_id = xhas won the game.
- DexTutor YT Playlist
- StackOverflow - for helping in fixing every error I got.
- Linux Man Page





