Lesson 3 of 5
Packets and Protocols
Learn how data is sliced into tiny packets, routed across networks, and stitched back together reliably.
Learn it
When you send a photo to a friend, the internet doesn't move the entire image in one heavy chunk. Instead, it chops the image into thousands of tiny digital parcels called packets!
Each packet takes the fastest route it can find through routers across the world. When they arrive, the recipient's computer uses numbered headers to put them back in the exact right order.
Key terms
- Packet
- A small formatted unit of data transmitted over a packet-switched network.
- Header
- Prefix data in a packet containing routing, sequence, and protocol instructions.
- TCP
- A connection-oriented protocol that ensures complete, error-checked, in-order delivery of packets.
- UDP
- A lightweight, connectionless protocol that sends packets quickly without delivery guarantees.
Simulating Packet Assembly
Explore how sequence numbers allow out-of-order packets to be reassembled accurately.
- 1Payload Fragmentation: A 1200-byte message is split into three 400-byte packet payloads.
- 2Header Tagging: Packets receive sequence tags: Packet 1 (Seq 0), Packet 2 (Seq 1), Packet 3 (Seq 2).
- 3Independent Routing: Packet 2 travels via satellite, while Packets 1 and 3 travel via terrestrial fibre.
- 4Buffer Reassembly: The destination receives Packet 1, then Packet 3, waits for Packet 2, and reorders them seamlessly.
Simulating TCP Packet Reassembly in Python
pythonpackets = [
{"seq": 2, "data": "World!"},
{"seq": 0, "data": "Hello "},
{"seq": 1, "data": "Digital "}
]
# Reassemble packets using their sequence number
sorted_packets = sorted(packets, key=lambda p: p["seq"])
reassembled_message = "".join(p["data"] for p in sorted_packets)
print(reassembled_message) # Outputs: Hello Digital World!Packets can arrive out of order across dynamic routes. Sequence numbers allow the receiving TCP stack to reconstruct the original data stream.
Try it
Complete the Python snippet to sort arriving network packets by their sequence ID:
arrived_packets = [{'seq': 3, 'chunk': 'end'}, {'seq': 1, 'chunk': 'start'}]
# Sort packets by sequence number
ordered = sorted(arrived_packets, key=lambda x: ______)
print(ordered[0]['chunk'])Challenge
Design a Python function that accepts a list of packets with missing sequence numbers and returns a list of missing packet IDs so TCP can re-request them.
Pick whichever way suits you — every mode earns the same bonus XP.
Write at least 40 more characters to submit.
Mark your own work
Guided walkthrough — 0/5 clues revealed
- Clue 1 locked — reveal it only if you get stuck.
- Clue 2 locked — reveal it only if you get stuck.
- Clue 3 locked — reveal it only if you get stuck.
- Clue 4 locked — reveal it only if you get stuck.
- Clue 5 locked — reveal it only if you get stuck.
Each clue costs 4 XP (never below 20 XP). You'd earn 40 XP right now.
Extension: Simulate packet loss by randomly dropping 10% of items from a test stream before reassembly.