Agree on a message format
Leans on
Quick review (2 minutes)
Two friends pass notes across a room through other people's hands.
A protocol is an agreed set of rules. In this unit's card protocol every data card holds, in order, To, From, Piece (a number of a total) and Data (from 1 to 4 characters); a card that breaks the format is not used.
List the fields the protocol requires, in order.
For each data card, check that every field is there.
Check that the fields are in the agreed order: To, From, Piece, Data.
Check the Piece field: a number from 1 up to the total, written as a number of the total.
Check the Data field: at least 1 and no more than 4 characters.
Mark the card as following the protocol only when every check passes.
A card that leaves out the total, Piece 2 instead of Piece 2 of 3, breaks the protocol, and the receiver cannot learn the total from that card. Keep both numbers.
A format that only one side knows is not a protocol. If Ana changes the data length to 5 characters without telling Kai, Kai's checks reject her cards.
1 In plain words
Two friends pass notes across a room through other people's hands. Everyone involved agrees first on how a note is written, so that each person who picks one up knows who it is for.
A protocol is an agreed set of rules for how a system behaves. The internet runs on protocols that anyone may use, which lets new devices join it.
This unit uses an invented paper protocol, the card protocol. Every data card carries four fields in this order (acknowledgment cards, in a later lesson, have a short form of their own): To, the receiver's name; From, the sender's name; Piece, written as a number of a total, such as 2 of 3; and Data, from 1 to 4 characters of the message. A card that lacks a field, or holds no data or more than 4 characters of it, breaks the protocol. The fields are this unit's own choice; real packets also carry their origin and destination.
Remember one sentence: a protocol is the rules both sides agreed on before the first message. To look it up, see essential knowledge CSN-1.B.3 in the AP Computer Science Principles Course and Exam Description.
2 Picture it
A table of the four fields of one card. To is Kai, who receives it. From is Ana, who sent it. Piece is 2 of 3, its place in the message. Data is -AT-, the content. The Piece row is marked.
3 Why
A receiver can act only on what the format promises. The To field lets a card be passed on toward the right person; the Piece field lets the pieces be put back in order and tells the receiver how many to expect. The AP course description says the same of internet packets: they carry data used for routing them and for putting the data back together.
Even a protocol that does not promise delivery has a formal structure: the Field Guide notes that UDP packets still carry their destination, their origin and their size.
Both sides must hold the same rules. A sender who writes the piece number last, or a receiver who expects data of 5 characters, cannot rely on the other side reading the card as it was meant.
4 The rule
A protocol is an agreed set of rules.
In this unit's card protocol every data card holds, in order, To, From, Piece (a number of a total) and Data (from 1 to 4 characters); a card that breaks the format is not used.
5 How
- List the fields the protocol requires, in order.
- For each data card, check that every field is there.
- Check that the fields are in the agreed order: To, From, Piece, Data.
- Check the Piece field: a number from 1 up to the total, written as a number of the total.
- Check the Data field: at least 1 and no more than 4 characters.
- Mark the card as following the protocol only when every check passes.
6 Trace
| Card | Problem | Follows the protocol? | Explanation |
|---|---|---|---|
| To Kai, From Ana, Piece 1 of 3, Data MEET | none | yes | All four fields, a valid piece number and 4 characters of data. |
| To Kai, From Ana, Data -AT- | no Piece field | no | Without a piece number the receiver cannot place it. |
| To Kai, From Ana, Piece 3 of 3, Data NOON. | 5 characters of data | no | The data field holds at most 4 characters. |
7 The trap
A card that leaves out the total, Piece 2 instead of Piece 2 of 3, breaks the protocol, and the receiver cannot learn the total from that card. Keep both numbers.
A format that only one side knows is not a protocol. If Ana changes the data length to 5 characters without telling Kai, Kai's checks reject her cards.
Quick checks
Quick check 1 of 2
A card reads To Kai, From Ana, Piece 2, Data NOON. Which rule of the card protocol does it break, and what can Kai not tell from it?
Show the steps and the answer
Its Piece field has no total, so Kai cannot tell how many pieces the message has.
Why: The protocol writes a piece as a number of a total, such as 2 of 3. Without the total, Kai cannot know when every piece has arrived.
Quick check 2 of 2
In one sentence, what is a protocol?
Show the steps and the answer
An agreed set of rules that specifies how a system behaves.
Why: The AP course description defines a protocol that way; the card protocol is one, agreed by sender and receiver.
Source: College Board, AP Computer Science Principles Course and Exam Description
Sources
- AP Computer Science Principles Course and Exam Description. College Board. All rights reserved. Read 2 Dec 2026.
- Computer Science Field Guide: Network Communication Protocols, 16.3 Transport layer protocols - TCP, UDP. University of Canterbury Computer Science Education Research Group. CC BY-SA 4.0. Read 2 Dec 2026.