Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Accept a Connection

Every HTTP request begins with a client connecting to a server over a transport layer. For HTTP, the standard transport layer is the Transmission Control Protocol (TCP).

TCP provides a reliable, ordered, and error-checked delivery of a stream of bytes between applications. Without TCP, HTTP wouldn’t know if the data it sent actually arrived!

Your Task

Bind a TCP listener to port 8080 on 0.0.0.0, wait for an incoming connection, and successfully accept it.

Warning

Why 0.0.0.0 and not localhost? If you bind your server to 127.0.0.1 (localhost), it will only accept connections from inside your host machine. Because our test suite runs inside a Docker container, it connects to your server via a virtual network bridge. Binding to 0.0.0.0 ensures your server listens on all network interfaces, allowing the Docker container to successfully reach it.


Important

Run the below docker command to test your solution.

docker run \
  --rm \
  --add-host host.docker.internal:host-gateway \
  codeberg.org/level0/buildit/http-server:latest \
  --addr host.docker.internal:8080 \
  --until accept_connection

Reference: RFC 9110 Section 3.3