In this assignment, you will deepen your understanding of network protocols by implementing a program in C or C++ of a "guessing game" where the server picks a random number between 1 and 100 and clients try to guess the number. The server will reply higher or lower to each guess. When a client guesses correctly, a message is sent to all connected clients telling them which client won, disconnects all clients, and resets the game.
The client and server executables should take one argument: the port that the server is listening on.
Example:
...source\Repos\GuessingGame:> GuessingGameServer.exe 2222Server listening on port 2222.
Client 1 connected.
Client 2 connected.
Client 1 disconnected.
Client 2 won! Resetting game ...
Welcome to the guessing game!
Guess a number between 1 and 100.
Your guess: 50
Too high.
Your guess: 75
Client 2 has won! Disconnecting ...
The client example program uses threads to handle blocking on input (stdin) as well as
blocking on receiving network traffic. It's simple but effective; one artifact of this
is that output to stdout must go through the safe_print mutex.
Your server will need to handle communication with multiple clients simultaneously - this can be through threads, using select(), etc. Your choice will determine if the server sockets need to be non-blocking or not.
You may find it helpful to create a simple protocol for the client and server: which side sends first? What does the response look like? How are the guesses sent, does the server return whether the game is over, etc.
This can (and should) be very simple -- don't over-complicate the protocol. In particular, using a serialization format like JSON is overkill.