Tis is a number guessing game based on TCP socket. The server side allows clients to guess a number between 0 to 999, and replies a guessing result, on the other hand, the client side can access the server, guess a number, and read the result replied by the server. Since this project is implemented by Windows Sockets API, it can only run on Windows system, but one shall be able to modify it into a Linux/Unix system version easily.
- Windows Sockets API
Loopback adapter is a network interface that can be used to route network traffic from one application to another on the same computer, but does NOT send that traffic to any other device on the network, which is useful to observe the behaviors on both server side and client side with only one Windows-system computer.
Wireshark is a free and open-source packet analyzer, one may use it to observe the communication between server and client in this project.
To get a local copy up and running follow these simple steps.
-
Clone the repo
git clone https://github.com/bob1113/tcp-number-guessing-game.git
-
Compile the
ser.cpp
andcli.cpp
filesg++ -o cli cli.cpp -lws2_32
g++ -o ser ser.cpp -lws2_32
-
Initialize server and client
Open two powershell windows, one for server side, and the other for client side.
Server.\ser 5555
Client
.\cli 127.0.0.1 5555
Game start Guess number Correct guess
The number used in .\ser 5555
is the port number that server and client communicate with, and the address 127.0.0.1
means that the client communicate with the server through loopback adapter, i.e., sending and receiving packets on the same computer.
Distributed under the MIT License. See LICENSE
for more information.
Bob Lai - [email protected]
Project Link - https://github.com/bob1113/tcp-number-guessing-game