Clean 3-way handshake
Client and server exchange SYN, SYN-ACK, and ACK. Both sequence spaces are independent, and the final ACK confirms the server ISN.
Trace SYN, SYN-ACK, ACK, sequence math, options, retries, and refused connections
Build a TCP connection one segment at a time. The workbench keeps the packet movement, endpoint states, sequence and acknowledgment numbers, option negotiation, and retry diagnosis synchronized so the handshake can be understood without a lecturer beside the screen.
Client and server exchange SYN, SYN-ACK, and ACK. Both sequence spaces are independent, and the final ACK confirms the server ISN.
A TCP connection is a reliable byte stream between two endpoints, identified by IP addresses and ports. It is not yet HTTP, MQTT, TLS, or an application login.
Each side proves that it can send and receive by exchanging sequence numbers and acknowledgments before ordinary data transfer.
SYN consumes one sequence number. If the client sends SYN with seq=x, the server acknowledges x+1 as the next byte it expects.
Every retry and extra round trip costs time, radio energy, and gateway state. This is why constrained designs often compare TCP with UDP-based protocols.
These cards turn the state machine into a guided task flow. A normal path uses the first four stages; loss and refusal scenarios make the diagnostic stages visible.
Client moves from CLOSED to SYN-SENT and offers its initial sequence number.
Server moves to SYN-RECEIVED, acknowledges the client ISN, and sends its own ISN.
Client acknowledges the server ISN. A pure ACK does not consume another byte number.
Both sides can exchange a reliable ordered byte stream after the setup completes.
Timeouts and retransmissions consume time and energy before the connection recovers.
A closed or rejecting port can answer with RST-ACK instead of entering ESTABLISHED.
The workbench keeps four views synchronized: connection state, sequence math, option negotiation, and design impact.
The client starts in SYN-SENT while the server is still LISTEN.
A peer acknowledges the SYN by asking for ISN + 1 next.
MSS, window scale, SACK permitted, and timestamps are advertised in SYN-bearing segments.
Radio sleep, weak coverage, and retransmissions can make connection setup dominate short IoT exchanges.
Use the table for fast recall, then open the notes when you need exact boundaries and implementation caveats.
| Segment | Flags | Sequence field | Acknowledgment field | State effect |
|---|---|---|---|---|
| Client request | SYN | x, the client ISN | Not meaningful unless ACK flag is set | Client enters SYN-SENT |
| Server response | SYN, ACK | y, the server ISN | x + 1 | Server enters SYN-RECEIVED |
| Client confirmation | ACK | x + 1 for a pure ACK | y + 1 | Client is ESTABLISHED; server becomes ESTABLISHED when this arrives |
| Refused port | RST, ACK | Implementation dependent | Usually x + 1 when answering a SYN | Attempt fails; no TCP connection is established |
TCP only creates a reliable ordered byte stream. TLS authentication and encryption, HTTP request semantics, and MQTT CONNECT/CONNACK are separate protocol work above that stream.
TCP sequence numbers count bytes in the stream, with SYN and FIN consuming one sequence number each. An ACK-only segment without data does not advance the sender's next sequence number.
TCP also defines less common paths where both sides actively open and exchange SYNs. This workbench focuses on the common active-client and passive-server path used by most IoT clients.
TCP Fast Open can allow data in the opening exchange when a valid cookie is available, but it is an extension. The main animation keeps application data separate so the base handshake remains clear.
Try these checks after watching the animation. The controls above give immediate feedback when the answer depends on RTT, sequence numbers, or retry path.
Set client ISN to 1000 and server ISN to 9000. Step to SYN-ACK and predict the two numbers that should appear in the response.
Raise RTT to 800 ms. Compare the clean path with lost SYN. Which event now dominates the time before data can flow?
Select option negotiation and name which pieces belong to TCP. Then decide what TLS, HTTP, or MQTT would still need to do afterward.
The calculations and labels in this workbench are based on current TCP specifications and option RFCs.
Current TCP specification, including header fields, sequence numbers, connection establishment, resets, and closing behavior.
RFC 7323TCP extensions for high performance, including window scale and timestamp options.
RFC 2018TCP Selective Acknowledgment options and SACK-permitted negotiation.
RFC 7413TCP Fast Open, included here only as an advanced caveat beyond the base 3-way handshake.