Packet switching: one hop at a time

A network is just a graph: nodes (computers and routers) and the links between them. A message is broken into packets, and each packet hops from node to node until it reaches its destination. Step through one packet's journey from A to D and watch its path light up.

Send a packet across a small network from A to D, one hop at a time, and record the path it took.

Packet switching — one hop at a time execution-derived · CPython model: author-asserted
same data, two zoom levels
state after line 1 runs
ABCD
path:

noteOur network: four nodes — A, B, C, D — and the links between them. This dict just says who connects to whom.

step 1 / 11

Click a line, drag the slider, or use the keys.

What you are looking at

The dict at the top is the whole network — each node listed with its neighbours. The packet starts at its source A, and on each hop it moves to the next node on its route, appending where it has been. Two hops later it reaches D, with a recorded path of A → B → D.

Real routers decide each next hop on the fly. Crucially, different packets of the same message can take different routes and still reassemble at the destination — that flexibility is what makes the internet robust when a link gets congested or fails.

This routing picture is not a hand-drawn diagram: it is a tiny Python simulation, traced like every other lesson. Model the process as code, trace it, and the animation falls out for free — see how GlassBox stays honest.