An HTTP server is a program that waits on a port for clients to connect. Today you open a listening socket and accept one connection, the raw foundation every later layer sits on.
Open a TCP listener on a port and accept a single incoming connection without error.
Before any HTTP exists, there must be a socket: an operating-system handle
for one end of a network connection. A server listens on an address, and each
time a client connects, Accept hands back a fresh connection you can read from
and write to.
Binding to port 0 asks the OS for any free port, which keeps tests from colliding on a fixed number. Read the real port back from the listener’s address so your test client knows where to dial. That is the whole handshake — bytes come next.
ln, err := net.Listen("tcp", "127.0.0.1:0") // :0 = OS picks a free port// ln.Addr() tells you which port you actually gotconn, err := ln.Accept() // blocks until a client connects_ = conn