This is a C++ project implementing a multithreaded TCP socket server capable of handling multiple clients concurrently using std::thread.
Each client connection is accepted and handled in a separate thread, allowing the server to manage simultaneous messaging in real-time.
- IPv4 TCP socket setup
- Multithreading using
std::thread - Handles multiple client connections concurrently
- Continuous message exchange with each client (not just once)
- Graceful disconnection handling per client
- Clean socket shutdown and resource management
- C++
- POSIX Sockets (
<sys/socket.h>,<netinet/in.h>) std::thread(C++11 threading)recv()/send()for communicationatomic<int>for assigning client IDs
- The server starts and listens on a defined port (default:
5000). - Each incoming client connection is accepted using
accept(). - A new thread is spawned per client using
std::thread. - The server continuously listens for messages from each client.
- Upon disconnection or failure, the thread closes that client’s socket and exits.
binding complete... Server is listening on port 5000... Accepted client [1] Accepted client [2] [client 1 ]: Hello from client 1! [client 2 ]: Hi server!
Let me know if you'd like to:
- Add screenshots or GIFs of terminals communicating
- Include a simple C++ or Python client in the repo
- Write a companion blog article for it
I can help with any of those too.