Skip to main content

Network Protocols and Sockets: Worked Examples

Work through each trace before reading the explanation. Then solve the transfer task without the page open.

Example 1: TCP does not preserve message boundaries​

A sender writes ABC and then DEF. The receiver may read AB followed by CDEF, or all six bytes together. Treating each read as one complete message misparses valid stream behavior.

Choose a framing rule, such as a fixed-width length header followed by that many payload bytes. Buffer incomplete headers and bodies, and retain bytes belonging to the next frame. Reject declared lengths above a configured limit before allocating.

Example 2: A timeout creates uncertainty​

A client sends a request, the server commits it, and the reply is lost. A timeout does not prove the operation failed. Blindly repeating a side effect can execute it twice.

Assign a stable logical operation identifier and define server-side deduplication or a status query when the application requires it. A transport retry by itself cannot guarantee exactly one business effect. Also bound total elapsed time across attempts, not only each attempt separately.

Transfer and self-check​

Two complete frames arrive in one read. What must the parser do? Check: emit both, or emit one while preserving the unread remainder; it must not discard trailing bytes.

Evidence to keep​

Save your first attempt, corrected reasoning, and transfer result as checkpoint evidence. A matching final answer without an explanation is insufficient. Continue with the guided lab and use the reading guide to repair a specific gap.