Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: James Smith

Rating 3.5 AI initial rating

“Learn network programming, the HTTP protocol, and its applications by coding your own Web Server.”

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide for developers who use HTTP every day but have never seen what happens below the browser: you build a working HTTP/1.1 server in Node.js from raw TCP sockets upward, learning the protocol's real semantics along the way. Best for intermediate programmers comfortable with JavaScript/TypeScript who want network fundamentals rather than another framework tutorial. 【Book Arc】 - **Opening (~0%–10%)**: Frames the "build your own X" philosophy and why coding a server teaches more than reading docs; surveys HTTP's evolution (1.0 → 1.1 → 2 → 3/QUIC) and shows command-line tools (nc, socat, curl, openssl) for inspecting raw traffic. - **Early (~10%–30%)**: Grounds you in TCP as a byte stream versus UDP packets, the socket primitives (listen/accept/read/write/close), and Node's event-loop-based concurrency — the mental model everything later depends on. - **Early–Middle (~30%–45%)**: Moves from callbacks to `async`/`await` and promises, then builds a small custom message protocol with dynamic buffers, pipelining, and backpressure — the bridge from "echo server" to "real protocol." - **Middle (~45%–65%)**: The HTTP core: message syntax and BNF, Content-Length vs. chunked transfer encoding, ambiguous edge cases, methods and their semantics (idempotence, cacheability), and text-vs-binary trade-offs. - **Late (~65%–85%)**: Applies HTTP in practice — range requests and 206 responses, caching validators (timestamps, ETags, Cache-Control), and compression via Node's Stream API with high-water-mark backpressure. - **Ending (~85%–100%)**: WebSocket upgrade and framing, plus a concurrency primer (race conditions, mutexes, blocking queues) used to build a WebSocket server integrated with the HTTP server. 【Key Takeaways】 - **TCP is a byte stream, not a packet stream** (Early): the book's "No. 1 beginner trap" is assuming read/write boundaries survive; protocols must impose their own message framing. This single idea justifies the whole socket chapter. - **Sockets are OS handles with a small primitive set** (Early): listening vs. connection sockets, half-open connections, and FIN/EOF behavior are explained before any Node API, so the `net` module code reads as a mapping onto concepts you already hold. - **Node's concurrency is event-based, not thread-based** (Early): callbacks, promises, and `await` are presented as ways to yield to a single-threaded runtime — essential for reasoning about why blocking code stalls a server. - **Backpressure is a first-class design concern** (Early–Middle): unbounded queues are called out as footguns; flow control appears at TCP, application, and stream levels, and the high-water-mark discussion ties them together. - **HTTP's hard parts are ambiguity and framing** (Middle): Content-Length, chunked encoding, and "nasty cases" show why a correct parser matters more than a fast one; methods are organized by idempotence and cacheability rather than memorized. - **Caching and range requests are protocol features you implement, not configure** (Late): validators (timestamps, ETags), TTL control, and 206/Content-Range responses are built step by step, revealing what CDNs and browsers actually negotiate. - **Compression interacts with everything** (Late): the book stresses the gotchas — Content-Length vs. chunked, caching, uploads, and range requests all change when you add `Content-Encoding`, motivating the Stream API refactor. - **Concurrency primitives make WebSocket servers tractable** (Ending): race conditions, mutexes, and blocking queues are introduced just in time to structure the WebSocket server's tasks and message flow. 【Reading Tips】 - Deep-read the TCP/socket and HTTP-semantics chapters; they carry the transferable knowledge. Skim the HTTP-evolution survey if you already know the 1.1-vs-2-vs-3 story. - Type the code rather than copying it — the book is project-centric, and the step-by-step builds (echo server, message protocol, compression, WebSocket) are where the learning happens. - Treat the end-of-chapter "Discussion" sections as the real payoff: they cover design choices, toy-vs-production gaps, and alternatives. Don't skip them when time is short. - Keep a terminal open with `nc`/`socat`/`curl -vvv` to poke at your server; the book deliberately teaches command-line inspection as a debugging habit. - If you're new to `async`/`await`, slow down in the Promises and Events chapter — later backpressure and stream material assumes it. 【Coverage Limits】 These excerpts cover the front matter, table of contents, and early-to-middle chapters in detail, but later chapters (range requests, caching, compression, WebSocket) are represented mainly by their section outlines; specific code and discussion content there is only partially visible.
Excerpt 1
mming Beyond Networking 3.7 Discussion: Promise-Based IO 04. Promises and Events 4.1 Introduction to `async` and `await` Using Callbacks Using Promises and `...
View in text
Excerpt 2
twork must conform to a specific format called a “protocol”. Learn how to create or implement any network protocols by using HTTP as the target. HTTP in Deta...
View in text
Excerpt 3
ckets || | ... | bottom The layer below TCP is the IP layer. Each IP packet is a message with 3 components: The sender’s address. The receiver’s address. The...
View in text
Excerpt 4
nection', newConn) registers the callback function newConn . The runtime will automatically perform the accept operation and invoke the callback with the new...
View in text
Excerpt 5
at this point, since our program is very simple. Some Node.js APIs, but not all of them, are available in both callback-based and promise-based styles. Howev...
View in text
Excerpt 6
te a wrapper from net.Socket function soInit (socket : net . Socket ) : TCPConn { const conn : TCPConn = { socket : socket , err : null , ended : false , rea...
View in text
Excerpt 7
t sends 'quit' , reply with 'Bye.' and close the connection. Otherwise, echo the message back with the prefix 'Echo: ' . client server ------ ------ msg1\n =...
View in text
Excerpt 8
ncreases the load time by at least one roundtrip time (RTT). If we can send multiple requests at once, without waiting for the responses one by one, the load...
View in text
Tags
AI categories
Programming LanguageBackend
Publish Year: 2024
Language: English
File Format: EPUB
File Size: 554.9 KB