Build a TCP chat server in Rust from scratch. We start with a single-client echo server,
watch it break when a second client connects, fix it with tokio::spawn, then turn echo
into chat using broadcast channels and tokio::select!. The episode covers the wrong
instinct most engineers have when reaching for Arc Mutex for shared state,
and why broadcast channels solve the problem more cleanly.
Code's at unsafehours.com/episodes/tcp-chat-server
CHAPTERS
0:00 The chat server we're building
5:25 Sync echo: the simplest thing that works
6:34 The blocking problem (and why one client breaks the server)
8:06 Converting to async with tokio
11:28 tokio::spawn and the future-vs-task distinction
15:46 broadcast::channel and tokio::select!
23:43 Final Message
ABOUT
Unsafe Hours is a YouTube channel covering Rust at depth — production patterns, language
internals, performance, systems programming. For engineers who want to be senior at Rust,
not just functional with it.
Code for every episode at unsafehours.com