Understanding TcpStream, what's the next step after accepting connection?
⚓ Rust 📅 2025-10-15 👤 surdeus 👁️ 6Hi everyone, I'm working through Chapter 21 of the Rust book (multithreaded web server).
I have a TcpListener that successfully accepts connections:
for stream in listener.incoming() {
let stream = stream.unwrap();
println!("Connection established!");
}
The terminal prints "Connection established!" when I visit the URL, but the browser just hangs.
Questions:
- Do I need to read from the stream first?
- Or should I write a response immediately?
- What's the minimum HTTP response format I need to send back?
I know I need to eventually parse HTTP requests, but right now I just want to understand the basic flow of:
- Accept connection → ??? → Send something → Close connection
2 posts - 2 participants
🏷️ Rust_feed