Course: Internet Architecture and Protocols [CS60008] – Chat Server Language: Python 3.9+
| # | 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 |
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.clientREGISTER alice password123
Then reconnect and:
LOGIN alice password123
/join general # join or create a room
/leave # return to lobby
/rooms # list all rooms
/subscribe bob # receive bob's messages even outside his room
/unsubscribe bob # stop receiving
/subscribers # who follows you
/subscriptions # who you follow
Enable Redis by setting environment variables:
USE_REDIS=true REDIS_HOST=localhost python -m server.serverRedis 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.
1. Generate certificates (once):
bash certs/generate_certs.sh2. Start TLS server:
USE_TLS=true python -m server.server3. Connect with TLS client:
USE_TLS=true TLS_CAFILE=certs/ca.crt python -m client.client# 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.clientUsers in the same room on different server instances still see each other's messages via Redis Pub/Sub.
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