AP Computer Science Principles · Unit 4 lecture · Part 4 of 11 · 9 min

4.1 Protocols: IP, TCP and UDPRules everyone agrees to follow

Mr. Thompkins
Imagine every phone company invented its own secret language for sending data. Your phone could talk only to phones made by the same company. The internet works because everyone agreed to speak the same languages, and nobody owns them.

A protocol is an agreed-upon set of rules that specify the behavior of a system. Two devices can exchange data only if they follow the same rules about how addresses are written, how data is split into packets, and what to do when something goes wrong.

The protocols of the internet are open, which means nonproprietary: they are published for anyone to read and use, and no company owns them. That's what lets a phone from one company, a router from another and a server from a third work together. It also makes it easy to connect new devices, which is why open protocols help the internet scale.

?Wait, what does "proprietary" mean?
Proprietary means owned and controlled by one company, often secret or requiring permission to use. Nonproprietary, or open, means published for anyone to follow. A phone charger that only fits one brand is proprietary; a USB-C plug is a shared standard.
ProtocolOne-word jobWhat it doesGood fit
IPRouteGives every device an address; routers forward packets toward the destinationEvery packet on the internet
TCPGuaranteeNumbers packets, checks they all arrived, has lost ones resent, puts them in orderFiles, email, web pages, bank data
UDPHurrySends packets with no delivery checks, so there is less delay but some may be lostLive calls, live video, game updates
HTTPServe pagesHow a browser asks for a web page and how the server sends it backThe World Wide Web
The four protocols the exam names. Learn the one-word job for each. The exam does not ask for the inner details of how they work.

IP, the Internet Protocol, handles addressing and routing. Every device on the internet gets an IP address, and routers forward each packet toward its destination address. IP on its own makes no promise that a packet arrives.

TCP and UDP run on top of IP and decide how carefully data is delivered. TCP, the Transmission Control Protocol, is the careful one. It numbers the packets, the receiver confirms what arrived, lost packets are sent again, and the packets are put back in order before the program sees them. UDP, the User Datagram Protocol, is the fast one. It just sends packets, with no checking and no resending, so there's less delay, but some packets may be lost or arrive out of order.

HTTP: the Web's requests and pagesTCP: reliableUDP: fast, no checksIP: addresses and routingwires, fiber, Wi-Fi, cell signaleach layer relies on the one below
Protocols build on one another. HTTP relies on TCP for complete delivery, TCP and UDP rely on IP to route packets, and IP relies on the physical connections.

TCP: reliable

  • Every packet arrives, or is sent again
  • Put back in order before delivery
  • Extra waiting when packets are lost
  • Files, email, web pages, payments

UDP: fast

  • No delivery checks, no resending
  • Packets may be lost or out of order
  • Low delay
  • Live calls, live streams, game updates
?Wait, isn't reliable always better?
Not always. Reliability costs time: to resend a lost packet, the receiver must notice it's missing and wait for it. For a file, that wait is fine. For a live call, waiting freezes the picture, and by the time the old piece arrives it's useless anyway.
Pause and think
In a live video call, one packet carrying 1/30 of a second of picture is lost. Predict what you see with UDP and what you would see if the app insisted on TCP and the network was busy.
I thought about it. Show me
With UDP, maybe a tiny glitch, and the call keeps going. With TCP, the app would wait for the lost packet to be resent before showing what came after it, so the picture could freeze for a moment. For live video, a small loss beats a freeze.
Analyze this scenario: TCP or UDP?
Choose TCP or UDP for each, with a reason: (a) a student uploads her essay to the school site; (b) a sports broadcast streams live; (c) a fast racing game sends each car's position 30 times a second; (d) a phone downloads an app update.
  1. Ask the same question every time: is it worse to lose a piece, or to wait for a piece?
    Why?
    This one question decides almost every TCP versus UDP item on the exam.
  2. (a) An essay with missing pieces is broken. Losing is worse: TCP.
  3. (b) Live means now. Waiting for an old piece makes the stream stall. Waiting is worse: UDP.
  4. (c) A position from a moment ago is useless once a newer one arrives. Waiting is worse: UDP.
  5. (d) An app with one wrong byte might not run. Losing is worse: TCP.

Answer: TCP for (a) and (d), where every byte must arrive. UDP for (b) and (c), where delay hurts more than a small loss.

Stuck? Get a hint
  1. Is the data still useful if it arrives late?
  2. Would a single missing piece break the whole thing?
  3. Files and updates must be complete. Live streams and live positions must be fast.
Check yourself
A startup builds a new fitness tracker that sends data to its owner's phone app over the internet. Why can it connect without getting permission from every company whose routers carry its data?
  1. AThe tracker uses UDP, and UDP needs no rules
  2. BThe internet's protocols are open, so any device that follows them can connect
  3. CEach router company sells a private protocol license to device makers
  4. DA government office approves every new device first
Show the answer

B. Open, nonproprietary protocols are published for anyone to follow, so any device built to them can join. The first choice is wrong twice: UDP is itself a set of rules, and it still relies on IP.

Check yourself
Which protocol is responsible for addressing devices and routing packets toward their destination?
  1. AHTTP
  2. BTCP
  3. CIP
  4. DUDP
Show the answer

C. IP routes. TCP and UDP decide how carefully packets are delivered, and HTTP is the Web's protocol for requesting pages. Giving routing to TCP is the most common mix-up.

Exam tip from Mr. T

Match each protocol to its one-word job: IP routes, TCP guarantees, UDP hurries, HTTP serves pages. Any answer choice that gives a protocol the wrong job, like "HTTP routes packets", can be crossed out on sight.

  • A protocol is an agreed-upon set of rules. The internet's protocols are open (nonproprietary), so anyone can build devices that join.
  • IP: addresses and routes packets. TCP: guarantees delivery and order, resending lost packets. UDP: sends with no checks, less delay, possible loss.
  • Choose TCP when losing data is worse, UDP when waiting is worse.