The Plain Picture#
A registered courier with a phone line. Before sending anything, the courier phones the receiver: "Ready?" — "Ready." Every parcel is numbered. The receiver phones back to confirm what arrived. Missing parcels are sent again. The receiver unpacks them in number order, so the contents come out exactly as sent.
The Real Name#
TCP (Transmission Control Protocol) turns IP's unreliable packets into a reliable, ordered stream of bytes between two programs. It promises:
Connection: both sides agree to talk before data flows (Ch 5).
Reliability: lost data is resent (Ch 6).
Order: bytes are delivered in the order they were sent (Ch 6).
No duplicates (Ch 6).
Flow and congestion control: the sender slows down if the receiver or the network can't keep up (Ch 7).
HTTP (the web), database connections, SSH and email all run on TCP.
A piece of TCP data in one packet is called a segment. A TCP header is at least 20 bytes.
Under the Hood#
TCP is a byte stream, not messages#
This trips up many people. If StudyBuddy writes "Hello" and then "World", the receiver might read
"HelloWorld" in one go, or "Hel" then "loWorld". TCP keeps the bytes in order but does not
keep message boundaries.
So every protocol built on TCP needs its own way to mark where a message ends — for example a length number at the start, or a special end marker. HTTP does this with headers (Networking 3: DNS, HTTP and HTTPS).
TCP vs UDP#
| TCP | UDP | |
|---|---|---|
| Connection | yes, handshake first | no |
| Delivery | guaranteed (or you get an error) | not guaranteed |
| Order | guaranteed | not guaranteed |
| Message boundaries | no — byte stream | yes — each datagram is one message |
| Slows down when needed | yes | no |
| Header | 20+ bytes | 8 bytes |
| Speed to first byte | slower (handshake) | immediate |
| Used for | web, APIs, databases, SSH | DNS, video/voice, games, QUIC |
Check yourself
3 questionsList TCP's five promises.
Show answerHide answer
Connection, reliability, order, no duplicates, flow/congestion control.
If a program writes "A" then "B" over TCP, will the receiver always get two separate reads?
Show answerHide answer
No — TCP is a byte stream; it might arrive as "AB" in one read.
Why is TCP used for databases but UDP for video calls?
Show answerHide answer
Database data must be complete and exact; for video, low delay matters more than every packet.