Software Design

TCP Connection State Machine

State Diagrams · made in Skemio

State diagram showing TCP states: LISTEN, SYN-RECEIVED, ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, TIME-WAIT, and CLOSED.
State diagram showing TCP states: LISTEN, SYN-RECEIVED, ESTABLISHED, FIN-WAIT-1, FIN-WAIT-2, TIME-WAIT, and CLOSED.

What it shows

  • A 3-way handshake transitions client and server safely into ESTABLISHED.
  • The active closer must enter TIME-WAIT to ensure late packets drain out.
  • Reusing sockets prematurely causes data corruption across sessions.

The takeaway

Understanding TIME-WAIT and connection teardown prevents socket exhaustion and silent packet drops.

More state diagrams