Skip to content

About

Multi-Client TCP Chat Server with Timeout Handling , created by Nour Brahim

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🖧 Multi-Client TCP Server with Timeout Handling

A simple yet robust Python socket server that supports multiple clients, handles connection timeouts, and shuts down after periods of inactivity.

🚀 Features

  • Multi-client support using threading
  • Idle client timeout handling
  • Server auto-shutdown after inactivity
  • Graceful disconnect handling
  • Clean & structured code for easy learning

📜 How It Works

The server:

  1. Binds to 0.0.0.0 and listens for incoming TCP connections.
  2. Accepts multiple clients concurrently via threading.
  3. Closes idle connections after a set timeout (default: 20s per client).
  4. Shuts down after 120s of inactivity with warnings at 60s.
  5. Sends confirmation for each received message.

The client:

  1. Connects to the server using the server’s IP and port.
  2. Sends messages with a header indicating their length.
  3. Disconnects when sending "disconnected" or an empty message.

🔧 Usage

1️⃣ Start the Server

python3 servercp.py

Server will start listening for incoming connections on port 5060.

2️⃣ Start the Client

python3 clientcp.py

Enter your messages. Send disconnected or leave the message empty to disconnect.

⚙️ Configuration

You can change these in the code:

PORT – Listening port (default: 5060)

HEADER – Message length header size (default: 64)

🔒 Security Enhancements (Future Work)

  • TLS/SSL encryption for secure communication

  • IP whitelisting / blacklisting

  • Authentication before message exchange

  • Logging of all incoming/outgoing traffic

👨‍💻 Author

Nour Brahim

📌 GitHub: https://github.com/NourBrahim

💼 LinkedIn: www.linkedin.com/in/nour-brahim777

About

Multi-Client TCP Chat Server with Timeout Handling , created by Nour Brahim

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages