Understanding TcpStream, what's the next step after accepting connection?

⚓ Rust    📅 2025-10-15    👤 surdeus    👁️ 1      

surdeus

Hi 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:

  1. Do I need to read from the stream first?
  2. Or should I write a response immediately?
  3. 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

Read full topic

🏷️ Rust_feed