Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Networking the lesson

TCP vs UDP, and the 3-way handshake a show in 8 chapters

Goal: send what matters over a network that promises nothing, and know who is on the line

1 of 8 Your guess

Before we start

You send a message to a friend across town. Between you sit many machines that pass it along, and none of them promises anything. A message can vanish, arrive late, or arrive claiming to be from someone it is not.

Which picture is closest to how a message gets across reliably anyway?

Pick the closest. You find out which fits at the end.

the intruderSan FranciscoShimomura'scomputersa machine they trustit never sent that cardfrom:the trusted one

2 of 8 The problem

Christmas Day, 1994

On December 25, 1994, the computers of a security researcher named Tsutomu Shimomura, working in San Diego, were broken into. The attack came from a machine in San Francisco, later traced to a well-known intruder, Kevin Mitnick.

No password was cracked by trial and error. What made the case famous was stranger: his computers were made to believe a message came from a machine they already trusted, when it did not.

Step 1 of 2

one message1234four cards, four packetseach with its own address

3 of 8 The idea

A packet is a postcard

A message crossing the internet is cut into chunks. Each chunk carries its own address on the outside, like a postcard, not a sealed truck with a driver who knows the whole route. One such chunk is a packet.

Your computer hands each packet to the network. Routers, machines that pass things along, move it toward the address. It either arrives or it does not, and nobody promises to tell you if it got lost.

Step 1 of 3

A UDP postcardfromroom2 bytestoroom2 byteshowlong2 bytesdamagecheck2 bytes4 × 2 = 8 bytesthen your message

4 of 8 Try it

UDP, the postcard

Given an address that is easy to fake and a room number that says who is home, there are two honest ways to hold a conversation. The plainest: write the postcard and send it, no questions asked. That is UDP.

It adds a return address, a room number, how long the message is, and a check that the card was not damaged. Each is 2 bytes, so 8 bytes of bookkeeping, and it stops there.

A byte is one small unit of data. One letter of plain text is about one byte.

Step 1 of 3

youyour friendhello?hello!the news: not yetFirst check someone is there.Only then say the news.

5 of 8 The fix

TCP, the phone call

The second way is to check the line is open before you say anything that matters. You pick up a phone and wait to hear an actual voice before launching into your news.

That is TCP. The check it runs before every conversation is the handshake: three messages, back and forth, before either side sends anything real.

Step 1 of 4

hellohello back13 ms= 1 round tripyour message so far: nothing

6 of 8 The cost

What the call costs

The line is not free. Nothing real can go until the hello has crossed and the hello back has returned. That wait is one round trip.

The lesson timed it on a real connection: the handshake took 12.9 ms, and the kernel's own estimate of the round trip was 13 ms.

ms is a millisecond, a thousandth of a second.

What changed

  • Wait before the first real byte: 0 ms → 13 ms

Step 1 of 5

7 of 8 Your guess

Your picture now

Goal met: a line you can trust, on a network that promises nothing. It cost 3 messages and one round trip, about 13 ms, before the first real word. Which picture is closest now?

Pick one.

TCP vs UDPA network promises nothing. A call is built at the two ends.UDP: the postcardNo setup. No checkit arrived.8 bytesof header, no promisesTCP: the phone callhello, hello back, okthen count every message.3 messagesbefore the first real wordThe price13 msOne round trip, measuredon a real line: 12.9 ms.52 msa cold page: 4 × 13chalkbrain.com
TCP vs UDPPostcards promise nothing.A call is built at the two ends.UDP: the postcardNo setup. No check it arrived.8 bytesof header, no promisesTCP: the phone callHello, hello back, ok.3 messagesbefore the first real wordThe priceOne round trip, 13 ms.52 msa cold page: 4 × 13chalkbrain.com

8 of 8 Keep this

Keep this

A network promises nothing, and a packet's return address can be faked. UDP is a postcard: 8 bytes, no promises. TCP is a phone call: hello, hello back, ok, with starting numbers each end must read back.

The price: one round trip, about 13 ms on this line, before the first real word. A cold page load pays 4 of them, 52 ms.

Read the full lesson