7 routes42 sections324 units

Unit 3.2 · about 4 h

250 / 324

TCP and UDP transport behavior

Sockets expose streams, not messages. Misreading TCP as a message protocol causes every framing bug in the next unit, and confusing flow control with congestion control misdirects tuning.

  • explain
  • measure

You can now

  • Explain the TCP service contract: reliable ordered duplicate-suppressed byte stream, setup cost, and what an ACK does not promise.
  • Contrast UDP datagrams with TCP streams and choose between them from loss, ordering and latency needs.
  • Read zero-window, retransmission and congestion evidence in a capture and name the limiting mechanism.

Covers

  • TCP connection setup, byte streams and flow control intuition
  • UDP datagrams and loss, duplicate and reorder behavior
  • Congestion-control mechanics and packet-capture analysis depth

Study, in this order

6 steps

  1. TCP versus UDP contracts
    AlgoMaster Networks - pcap and concurrent server labs

    TCP's Service Contract (reliable, ordered, duplicate suppression, byte stream); UDP's Service Contract; Message Size Matters

  2. The TCP three-way handshake
    AlgoMaster Networks - pcap and concurrent server labs

    Step 1 through Step 3; Sequence Number Arithmetic; Why Three Messages Are Necessary; Listening Queues and Server Load

  3. Reliability and flow control
    AlgoMaster Networks - pcap and concurrent server labs

    Reliability Is Defined Over Bytes; An ACK Is Not an Application Receipt; Gaps and Duplicate ACKs; Retransmission Timeout; then Flow Control and the Sliding Window: Receive Buffers and Application Reads, Zero Window, Diagnosing a Flow-Control Stall

    Depth · Use https://algomaster.io/learn/computer-networks/flow-control-sliding-window for the flow-control sections.

  4. TCP and UDP path in Beej's Network Concepts
    Beej's Guide to Network Concepts - TCP and UDP path

    Chapter 14, TCP (Sections 14.4.1, 14.4.2 and 14.6); Chapter 15, UDP (Sections 15.4, 15.6 and 15.7)

  5. A real zero-window stall
    AlgoMaster Networks - pcap and concurrent server labs

    Turn the Stream into a Timeline; Inspect the Edges of the Gap (zero-window evidence); the host-correlation conclusion

    Depth · Follow the phase method and the window evidence. The audit-pipe root cause is one example of host correlation, not a pattern to memorize.

  6. Congestion control vocabulary (optional topic)
    AlgoMaster Networks - pcap and concurrent server labs

    Flow Control and Congestion Control Solve Different Problems; Slow Start; Congestion Avoidance and AIMD

    Depth · Vocabulary only for the optional topic. No measurement required; stop before the variant comparison.

Focus on

  • TCP numbers bytes, not messages. The ACK advances over the contiguous prefix; a gap stalls acknowledgment even when later bytes arrived.
  • An ACK means the peer kernel holds the bytes. It does not mean the application read or acted on them.
  • Flow control (receiver window) and congestion control (sender network estimate) are independent limits; the sender obeys the smaller.
  • UDP preserves message boundaries and promises nothing else. Loss, duplication and reordering are normal and must be handled above it.

Reproduce closed-book

Closed-book, write the three handshake messages with initial sequence numbers (client \(c\), server \(s\)) and the ACK numbers \(c+1\) and \(s+1\). Then, on loopback with CPython 3.14.4, run a server thread that accepts and closes, and time 100 create_connection plus close calls after 10 warm-up ones; then time 200 round trips of a 4-byte length-prefixed echo (TCP_NODELAY, 20 warm-up) at 64 bytes and 64 KiB. Pinned to two performance cores with taskset -c 2,4 on an i9-12900K with Linux 7.0, three runs gave connect plus close medians of 12 to 16 us, a 64 B echo p50 of about 9 us and a 64 KiB p50 of about 29 us; unpinned runs that landed on efficiency cores were up to about twice as slow. Record yours with the same setup and say which cores ran it.

Traps

  • Calling a retransmission proof of packet loss. Delayed ACKs, reordering and spurious timeouts cause retransmissions on healthy paths.
  • Expecting close to deliver pending application work. A graceful FIN ends the byte stream; it says nothing about processed requests.
  • Treating UDP as TCP without acknowledgments. Without sequence numbers and reassembly above it, duplicates and reordering reach the application.

Practice

AlgoMaster: Reassemble TCP Segments

nextExpected over out-of-order overlapping [seq, length] intervals under the contiguous-prefix rule

The gap example ([[0,3],[5,2]] returns 3) is the ACK rule in code; overlapping intervals must not double-count.

Self-test

  1. Segments \([0,3)\) and \([5,7)\) arrived. Which byte does the receiver ACK next?

  2. The client advertised a zero window for five seconds, then the transfer resumed with no retransmissions. Where was the stall?

  3. Why does a fresh TCP connection cost at least one round trip before data flows?

  4. Two identical datagrams arrive over UDP. Did the network duplicate one, or did the sender retransmit?

Completion criterion

Stop when

You classify a stall as receiver-window, loss-recovery or endpoint silence from window and ACK evidence, and your reassembler returns 3 and 5 on the two worked examples.

Mark passed, then open 3.3 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • Beej's Guide to Network Concepts - TCP and UDP path
    Brian Hallrequiredtheory
    Read the OS and sockets, protocol layering, IP, UDP and TCP chapters alongside packet captures from your own client and server. Use it to explain transport behavior rather than memorize layer names.
  • AlgoMaster Networks - pcap and concurrent server labs
    AlgoMasterrequiredpractice
    Use Reading a Packet Capture: A Real Bug and Building a Concurrent TCP Echo Server after the Beej implementation. Reproduce one packet-level observation and one admission, deadline or shutdown behavior in your independently written service.

Also in this section

  • Beej's Guide to Network Programming - sockets to multiplexing
    Brian Hallprimarycourse
    Read What is a socket?, IP addresses and data structures, Client-server background, System calls or bust, Client-server examples, Slightly advanced techniques and sendall. Build the simple TCP pair first, then replace delimiter assumptions with a bounded length-prefixed protocol.
  • MIT 6.5840 - RPC, threads and fault vocabulary
    MIT PDOSsupporttheory
    Read the introductory RPC and threads material plus the lab guidance. Use it to enumerate timeout ambiguity and duplicate effects. Stop before Raft and the full lab sequence.
  • Replicated Log and Stream Processor - protocol slice
    Roadmap-Finalsupportproject
    Use only the protocol requirements, deterministic network fault matrix and delivery-contract questions. Build the single-node framed service now; keep replication and consensus for the later project.
  • Designing Data-Intensive Applications, 2nd edition - Chapter 5
    O'Reillyrequiredtheory
    Read Formats for Encoding Data (printed pp. 163 to 177) for schema merits and compatibility, and Dataflow Through Services: REST and RPC (printed pp. 180 to 186) for service dataflow, version coexistence and the idempotence pointer.
  • gRPC Deadlines guide
    gRPC Authorsreferencereference
    Read Overview, Deadlines on the Client and Deadline Propagation for absolute deadlines, remaining-time forwarding and clock-skew shielding.
  • gRPC Status Codes
    gRPC Authorsreferencereference
    Read the full status list, including DEADLINE_EXCEEDED, UNAVAILABLE and the codes never generated by the library, for the error taxonomy.
  • W3C Trace Context
    W3Creferencereference
    Read Section 3.2 for the traceparent format and Sections 3.4 to 3.5 for the legal traceparent and tracestate mutations when forwarding.

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels