Interactive LabRuns in your browser

TCP State Machine & Sliding Window

TCP 3-way handshake, 4-way termination, and sliding window congestion control simulator.

Speed:

About this tool

TCP turns an unreliable packet network into a reliable byte stream. Before data flows, the two ends synchronize sequence numbers with a three-way handshake; when they are done, each direction is closed separately with a four-way teardown. While data flows, congestion control decides how many segments may be in flight, growing the window until the network signals trouble by losing packets.

This lab has three views: an animated sequence diagram of the handshake, one of the teardown with every state transition (SYN_SENT, FIN_WAIT_2, TIME_WAIT and the rest), and a congestion-window chart where you inject losses and compare TCP Tahoe with TCP Reno.

How to use TCP State Machine & Sliding Window

  1. Open the handshake view and step through SYN, SYN+ACK and ACK. Note how each ack number is the other side’s sequence number plus one.
  2. Switch to the teardown view and follow both sides from ESTABLISHED to CLOSED, including the half-closed phase.
  3. In the congestion-control view, pick Tahoe or Reno and play the chart: exponential slow start, then linear congestion avoidance above ssthresh.
  4. Add a triple-duplicate-ACK loss or a timeout at any round and compare the segments delivered by both algorithms.

Examples

Handshake numbers

Input
Client ISN 1000, server ISN 5000
Result
SYN seq=1000 → SYN+ACK seq=5000 ack=1001 → ACK seq=1001 ack=5001

Reno vs. Tahoe on 3 duplicate ACKs

Input
cwnd = 16 when the loss is detected
Result
Reno: ssthresh = cwnd = 8, keeps growing linearly. Tahoe: ssthresh = 8, cwnd = 1, slow start again

Why three and four messages?

Each side must announce its own initial sequence number and see it acknowledged; the server combines its SYN with its ACK, giving three messages. Closing takes four because each direction closes independently — the server may still have data to send after the client is done.

Congestion-control vocabulary

  • cwnd: congestion window, the number of unacknowledged segments the sender allows itself.
  • ssthresh: slow-start threshold, where growth switches from doubling per RTT to +1 per RTT.
  • Three duplicate ACKs: a mild signal (later packets still arrive). A retransmission timeout: a severe one.
  • Modern Linux defaults to CUBIC, and Google’s BBR models bandwidth and RTT instead of reacting only to loss.

Frequently asked questions

Everything you need to know about this tool and data security.

Why does TIME_WAIT last 2×MSL?

So that a lost final ACK can be retransmitted when the peer resends its FIN, and so that stray old segments expire before the same port pair is reused.

Why are initial sequence numbers random?

To avoid confusing segments from an old connection with a new one, and to make it hard for an attacker to inject forged segments.

What is the difference between flow control and congestion control?

Flow control (the receive window) protects the receiver from being overwhelmed. Congestion control (cwnd) protects the network. The sender uses the smaller of the two.

Is my data safe when using this tool?

Yes, 100% safe. This tool operates entirely inside your web browser using client-side JavaScript and WebAssembly. Your data never touches any external server.