Multi-threaded Chat Server over TCP
Build a chat server using raw TCP sockets and threads where multiple clients can connect, choose a username, and broadcast messages to all connected clients. Learners practice std::net TCP sockets, thread-per-connection concurrency, and safely sharing state across threads with Arc and Mutex.
- Estimate
- ~9h
- Steps
- 5
- Completed by
- 0
- Proposed by
- codeseed.app
std::net
Project roadmap
- 01
Accept TCP connections
~1.5hSet up a TcpListener that accepts incoming connections and spawns a thread per client.
- 02
Handle client usernames and messages
~1.5hPrompt each connecting client for a username and read incoming messages in a loop.
- 03
Broadcast messages to all clients
~2.5hUse Arc<Mutex<Vec<Sender>>> or channels to broadcast each client's message to all other connected clients.
- 04
Handle client disconnects
~1.5hDetect when a client disconnects, remove them from the broadcast list, and notify remaining clients.
- 05
Build a simple CLI client
~2hWrite a companion client binary that connects to the server and lets a user chat from the terminal.
Resources
- DocsThe Rust Book
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack