Async Chat Server (Python asyncio)
Implement a TCP chat server using Python asyncio.
Part 1 — Single global room
Your server listens on a given port and supports multiple concurrent clients.
Protocol (line-based text):
-
When a client connects, the server prompts for a
username
(single line).
-
After login, each line a client sends is treated as a chat message.
-
The server
broadcasts
each message to all
other
connected clients in the format:
Behavior requirements:
-
A client should not receive its own message back.
-
Handle client disconnects gracefully (no crashes; cleanup resources).
-
The server should continue serving other clients if one client misbehaves (e.g., disconnects mid-line).
Part 2 — Basic chat commands
Extend the protocol to support:
-
/join <room>
: join (and create if needed) a named room.
-
Each user is in exactly
one room at a time
.
-
After joining, broadcasts only go to users in the
same room
.
-
/who
: return the list of usernames currently in the user’s room.
-
/quit
: disconnect.
Constraints / assumptions:
-
Up to ~1,000 concurrent connections.
-
Use only standard library (
asyncio
/
socket
/ etc.).
-
Favor clear concurrency handling and correctness over advanced features (no persistence required).