Transmission Control Protocol (TCP) is the bedrock of reliable network communication. For senior engineers, understanding TCP goes beyond "it guarantees delivery." It requires a grasp of how state is maintained, how connections are uniquely identified, and how the protocol handles the inherent unreliability of the IP layer.
The TCP Header and Multiplexing
A TCP segment consists of a header and a data section. The header contains critical control information:
- Source & Destination Ports: (16 bits each) Identify the specific process or service endpoints. Combined with Source IP and Destination IP, these form the 4-tuple that uniquely identifies a TCP connection.
- Sequence Number (SEQ): (32 bits) If the SYN flag is set, this is the initial sequence number (ISN). Otherwise, it marks the index of the first data byte in this segment.
- Acknowledgment Number (ACK): (32 bits) If the ACK flag is set, this is the value of the next sequence number the sender is expecting to receive.
- Flags (Control Bits):
- SYN: Synchronize sequence numbers (initiate connection).
- ACK: Acknowledgment field is significant.
- FIN: No more data from sender.
- RST: Reset the connection.
- PSH: Push function (buffer flush).
- URG: Urgent pointer field is significant.
- Window Size: The number of data octets the sender is willing to accept (Flow Control).
The 3-Way Handshake (Connection Establishment)
Before data transfer, TCP establishes a logical connection. This synchronizes the sequence numbers.