Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-threaded Chat Server

Course: Internet Architecture and Protocols [CS60008] – Chat Server Language: Python 3.9+

Problems Implemented

# Problem Status
1 Thread-based server with blocking I/O
2 Authentication with bcrypt password hashing
3 Force logout on duplicate login
4 Chat rooms (/join, /leave, /rooms)
5 Publish–Subscribe (/subscribe, /unsubscribe)
6 Redis integration (distributed state, multi-server)
7 TLS/SSL encrypted transport
8 Docker deployment

Quick Start (No Docker)

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

# Start server
python -m server.server

# Start one or more clients (in separate terminals)
python -m client.client

Usage

Register

REGISTER alice password123

Then reconnect and:

LOGIN alice password123

Room commands (Problem 4)

/join general        # join or create a room
/leave               # return to lobby
/rooms               # list all rooms

Pub-Sub commands (Problem 5)

/subscribe bob       # receive bob's messages even outside his room
/unsubscribe bob     # stop receiving
/subscribers         # who follows you
/subscriptions       # who you follow

Problem 6 – Redis (Multi-server)

Enable Redis by setting environment variables:

USE_REDIS=true REDIS_HOST=localhost python -m server.server

Redis schema:

Key Type Contents
session:<user> HASH {server_id, addr}
room_members:<room> SET set of usernames
user_room:<user> STRING current room name
chat_broadcast Pub/Sub channel cross-server messages

If Redis is unavailable the server falls back to in-memory state automatically.


Problem 7 – TLS

1. Generate certificates (once):

bash certs/generate_certs.sh

2. Start TLS server:

USE_TLS=true python -m server.server

3. Connect with TLS client:

USE_TLS=true TLS_CAFILE=certs/ca.crt python -m client.client

Problem 8 – Docker

# Start everything (Redis + 2 server instances)
docker-compose up --build

# Connect to server 1 (port 5555) or server 2 (port 5556)
python -m client.client
SERVER_PORT=5556 python -m client.client

Users in the same room on different server instances still see each other's messages via Redis Pub/Sub.


Project Structure

chat-app/
├── server/
│   ├── server.py            # ChatServer – accepts connections, manages state
│   ├── client_handler.py    # Per-client thread – parses and dispatches commands
│   ├── auth.py              # AuthManager – bcrypt registration/login
│   ├── room_manager.py      # RoomManager – room membership (in-memory)
│   ├── subscription_manager.py  # SubscriptionManager – pub-sub (Problem 5)
│   ├── redis_manager.py     # RedisManager – distributed state (Problem 6)
│   └── config.py            # All config + env-var overrides
├── client/
│   └── client.py            # CLI client with optional TLS (Problem 7)
├── certs/
│   └── generate_certs.sh    # Self-signed CA + server cert generation
├── Dockerfile
├── docker-compose.yml
└── requirements.txt

About

Multi-threaded chat server with authentication and room support

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages