Simple TCP Server-Client is a basic C++ application implementing a client-server model using the Asio library for asynchronous input-output operations.
The server can accept connections from clients, handle incoming messages, and log them. The client supports periodic message sending to the server at a defined interval.
This project is being developed for self-educational purposes, but it can be used for any of your tasks. In particular, you can build something more complex using the example provided in the existing main.cpp.
- Asynchronous acceptance of client connections.
- Logging of incoming messages.
- Multithreaded handling of each connection.
- Connect to the server by IP and port.
- Periodic message sending with a specified interval.
- Automatic retrying of message sending after successful connection.
- Unix-type system
- CMake 3.18+
- C++11 compatible compiler
- vcpkg (for asio)
- Asio library
Cmake install
Debian / Ubuntu
sudo apt update sudo apt install cmakeFedora
sudo dnf install cmakeCentOS/RHEL
sudo yum install cmakeArch
sudo pacman -S cmakevcpkg install
git clone https://github.com/microsoft/vcpkg.git./bootstrap-vcpkg.sh
./vcpkg integrate install
Asio install
./vcpkg install asio --head
-
Clone the repository:
git clone https://github.com/CrispusCrew/IP_simpleTCP.git cd IP_simpleTCP -
Build the project with CMake & install the binaries:
chmod a+x build.sh # if nessesary ./build.sh
-
Start the server, specifying the port to listen on by args:
./bin/server <port>
-
Or use cmd input after start
./bin/server Enter portTCP <port>
-
Stop server by typing "exit" or simple "e"
exit
-
Start the client, specifying the client name, port and ping period on by args:
./bin/client <portTCP> <clientMsg> <pingPeriod>
-
Or use cmd input after start
./bin/client Enter clientMsg, portTCP and pingPeriod <portTCP> <clientMsg> <pingPeriod>
-
You also can use float value of pingPeriod (for example every 0.5 seconds)
./bin/client name1 12345 0.5
-
Stop client by typing "exit" or simple "e"
exit