TCP Connection Management: Establishment, Closing, and Connection States
TCP Connection Management
A TCP transport connection has three stages: establishment, data transfer, and release. Connection management controls establishment and release so they operate correctly.
Connection establishment is called the three-way handshake:
- First: the client application actively opens and sends a request segment with SYN=1 and seq=x.
- Second: the server application passively opens and, if it accepts the request, sends a segment with SYN=1, ACK=1, ack=x+1, and seq=y.
- Third: after receiving the confirmation, the client notifies its application that the connection is established and sends ACK=1, ack=y+1. When the server receives this acknowledgment, it also notifies its application that the connection is established.
Establish a connection and retry a lost SYN-ACK
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Connection Release
Connection release is called a four-message closing exchange:
- First: after data transfer, the client application sends a release segment with FIN=1, seq=u, and stops sending data.
- Second: the server acknowledges with ack=u+1, seq=v. The connection is now half-closed: the client no longer sends data, but the server may continue sending.
- Third: when the server has no remaining data, its application requests release. The server's final segment carries FIN=1, ACK=1, seq=w, and ack=u+1.
- Fourth: the client acknowledges with ACK=1, seq=u+1, ack=w+1. After twice the Maximum Segment Lifetime (MSL), the connection truly ends.
Keep receiving after a half-close
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Connection States and TIME-WAIT
A typical active closer traverses ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, TIME-WAIT, and CLOSED; the passive closer traverses ESTABLISHED, CLOSE-WAIT, LAST-ACK, and CLOSED. TIME-WAIT permits re-ACKing a duplicate FIN if the final ACK was lost and allows old segments to expire before the connection identifier is reused.
The diagrams separate the four closing segments, but implementations may combine ACK and FIN, and both endpoints may close simultaneously. RST resets a connection rather than performing an orderly FIN close.
Number a handshake and an orderly close
Handshake ISNs are100/500. After establishment, with no client data sent, the client closes. The server ACKs, sends8 data bytes, then FINs. List handshake and closing Seq/ACK values and key states. What happens if the first SYN-ACK is lost? How long is TIME-WAIT when MSL=30 s?