TCP: Byte Streams, Segment Structure, Sequence Numbers, and Acknowledgments
TCP Segment Structure
The main TCP header fields are:
- Source/destination ports: multiplex and demultiplex application data.
- Checksum: detect errors.
- Sequence/acknowledgment numbers: implement reliable transfer.
- Receive window: provide flow control by indicating how many bytes the receiver is willing to accept.
- Header length: options make the header length variable. With no options, its typical length is 20 bytes.
- ACK: indicate that the acknowledgment field is valid.
- RST/SYN/FIN: establish and tear down connections.
Inspect TCP header fields
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Sequence and Acknowledgment Numbers
Both ends can randomly choose initial sequence numbers, reducing the chance that residual segments from a previous TCP connection are mistaken for segments of a new connection that happens to use the same port.
Host A's acknowledgment number is the next byte sequence number it expects from B. TCP acknowledges only bytes through the first missing byte, so it provides cumulative acknowledgments.
Telnet is an application-layer remote-login protocol running over TCP. Suppose A initiates a Telnet session with B. Every typed character is sent to B, which returns a copy to A for display, confirming that the character was processed.
Suppose A and B have initial sequence numbers 42 and 79. Each character typed by the user crosses the network twice.
KNOWLEDGE QUIZ
TCP Provides a Byte Stream, Not Message Boundaries
TCP numbers bytes, and a segment's sequence number identifies its first data byte. The same application stream can be split into different segment sizes; a receiver's read need not match a sender's write. Applications need length prefixes, delimiters, or another framing rule.
The echo diagram starts at the first data bytes of an established connection. SYN consumes one sequence number during establishment, and FIN consumes one during closing; a pure ACK consumes none. The two transmission directions have independent sequence spaces.
Reassemble a byte stream across gaps
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Trace byte gaps and a character echo
The receiver expects92. It receives Seq100,len20, then Seq92,len8, then a duplicate Seq92,len8; assume out-of-order buffering. Give each ACK and newly deliverable bytes. Separately, A's next data sequence is42 and B's is79: A sends C, B echoes C, then A ACKs. Give Seq/ACK for all three segments.