indexFundamentos de TCP#tcp#sockets#networking
Esta nota todavía no está traducida, así que se muestra la fuente en inglés.

TCP Fundamentals

The entry point into this atlas: a TCP echo server so simple it fits on one screen, understood so thoroughly there's nothing left unexplained underneath it. This is where "a socket is a file descriptor" (Atlas I, Atlas II) becomes "I know exactly what happens on the wire and in the kernel between connect() and the first byte of data" — the three-way handshake, TCP_NODELAY and why Nagle's algorithm exists, send/recv buffers and what backpressure actually feels like from inside a program, half-close, and every network failure mode that a tutorial usually glosses over.

Builds directly on Atlas II's HTTP Server from Scratch — the socket calls are the same socket/bind/listen/accept family, but this branch stops at the transport layer instead of layering HTTP on top of it, and goes deeper into the mechanics that branch didn't need.

Planned notes

  • socket, bind, listen, accept, connect — a second look, this time at the kernel state each call creates
  • The three-way handshake traced with a packet capture: SYN, SYN-ACK, ACK, and what a half-open connection looks like
  • TCP_NODELAY and Nagle's algorithm: why small writes get delayed, and when to turn that off
  • Socket send/recv buffers: SO_SNDBUF/SO_RCVBUF, and what happens when a buffer fills
  • Backpressure: what a slow reader does to a fast writer, and how to detect it from write()'s return value
  • Half-close with shutdown(): why closing a socket isn't one operation
  • Blocking vs non-blocking sockets and O_NONBLOCK, as a precursor to the event loop
  • Timeouts: SO_RCVTIMEO, SO_SNDTIMEO, and why relying on the OS default is a bug waiting to happen
  • Detecting a dead peer: RST vs a silently hung connection, and why you need heartbeats even at this layer
  • Building the v0 echo server, then breaking it on purpose: a client that reads one byte at a time, a client that never reads

Core sources

  • Beej's Guide to Network Programming — free, the backbone of this entire branch.
  • TCP/IP Illustrated, Volume 1 (Stevens) — deep reference for the handshake, teardown, and flow control internals.
  • man tcp, man setsockopt — read the man pages, not just tutorials about them.

Connects to: Custom Binary Protocol · Connection Concurrency at Scale