liveBook · Manning

TCP

As explained in Rust in Action: Systems programming concepts and techniques

TCP (Transmission Control Protocol) is a transport-layer network protocol that provides reliable, ordered, connection-oriented delivery of data.

TCP (Transmission Control Protocol) sits below HTTP and TLS in the networking stack, carrying application data over an established connection while lower protocols handle transmission details. section 8.1

TCP becomes concrete through two progressively lower-level approaches:

  • Use Rust’s std::net::TcpStream to connect to a host, write an HTTP GET request, add the Host header, and copy the response to standard output. section 8.4
  • Use smoltcp TCP primitives inside a manually assembled HTTP client, coordinating Ethernet, DNS resolution, URL parsing, and socket state. section 8.10
  • Account for the boundary between names and network connections: TcpStream connects using an IP address, while the HTTP Host header supplies the hostname context. section 8.4

A minimal HTTP request over TCP

A Rust program connects to www.rustinaction.com:80, writes "GET / HTTP/1.0", terminates the request lines with CRLF, adds "Host: www.rustinaction.com", and streams the response to stdout. HTTP/1.0 is chosen so the server closes the connection after responding. section 8.4

Raw TCP work exposes operating-system boundaries: raw network requests typically require superuser access, while a Linux proxy device can provide direct access to non-superusers. A minimal client can model connection, request, and response states. section 8.8

Figure 8.2 Several layers of networking protocols involved with delivering content over the internet. The figure compares some common models, including the seven-layer OSI model and the four-layer TCP/IP model.

Compare the OSI and TCP/IP networking models to see TCP’s position among HTTP, TLS, Ethernet, and lower transmission layers. section 8.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Progresses from TcpStream usage to TCP socket states and raw-packet access, but does not detail TCP’s internal reliability algorithms.
Examples
Demonstrates TCP with a Rust HTTP GET client, a smoltcp-based mget project, DNS queries, and a virtual networking device.
What it assumes
Assumes basic Rust and HTTP familiarity while introducing networking layers, socket connections, DNS resolution, and raw-device constraints.
What you can do after
Build it from scratch by sending HTTP requests with TcpStream or a virtual device and minimal TCP implementation.
How it connects
Ties TCP to HTTP, TLS, DNS, IP, Ethernet, and operating-system networking privileges.

Also explained in

Compare how 5 books explain TCP →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.