Skip to content

Pushpak2861/Socket-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multithreaded Multi-Client Socket Server in C++

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.


Features

  • 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

Technologies Used

  • C++
  • POSIX Sockets (<sys/socket.h>, <netinet/in.h>)
  • std::thread (C++11 threading)
  • recv() / send() for communication
  • atomic<int> for assigning client IDs


How It Works

  1. The server starts and listens on a defined port (default: 5000).
  2. Each incoming client connection is accepted using accept().
  3. A new thread is spawned per client using std::thread.
  4. The server continuously listens for messages from each client.
  5. Upon disconnection or failure, the thread closes that client’s socket and exits.

Sample Output

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.

About

Multi client application

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages