Article
TCP, the reliable way
You download a program to install. If even one small piece is missing, the program may not run at all. Here a glitch is not acceptable. You want every byte, correct and in order. A protocol called TCP is built for exactly that.
TCP: make sure it all arrives
TCP (Transmission Control Protocol) is a protocol that makes the sending of packets reliable. It works together with IP: IP still addresses and routes the packets, and TCP adds the checking. TCP does these things:
- It sets up a connection first. The two computers agree to talk before data is sent.
- It numbers the packets, so the receiver knows which piece is which.
- The receiver sends back an acknowledgement. An acknowledgement is a short message that says "I got packet 4".
- The sender resends packets that are not acknowledged. If no acknowledgement comes back after a short wait, the sender assumes the packet was lost and sends it again.
- The receiver puts the packets in order, throws away any copy it already has, and checks that the data was not damaged.
Here is a lost packet being repaired:
TCP repairs a lost packet
- 1
Sender → Receiver
Can we talk?
- 2
Receiver → Sender
Yes, ready.
- 3
Sender → Receiver
packet 1
- 4
Receiver → Sender
got 1
- 5
Sender → Receiver✕ lost
packet 2
- No acknowledgement for packet 2 comes back, so the sender waits and then sends it again.
- 6
Sender → Receiver
packet 2 again
- 7
Receiver → Sender
got 2
The sender never knew why packet 2 vanished. It only noticed that the acknowledgement did not come, and that was enough.
Check your understanding
A sender uses TCP. It sends packet 7, but no acknowledgement for packet 7 comes back. What does TCP do?
The price of reliability
All this checking takes time. TCP has to set up the connection, wait for acknowledgements, and sometimes wait for a lost packet to be sent again. So TCP is usually slower than UDP and can have more delay. Here are the two protocols side by side:
| UDP | TCP | |
|---|---|---|
| Sets up a connection first | No | Yes |
| Acknowledgements | No | Yes |
| Resends lost packets | No | Yes |
| Puts packets in order | No | Yes |
| Speed and delay | Faster, lower delay | Slower, more delay |
| Good for | Live calls, games | Files, programs, web pages, email |
Use TCP when every bit must arrive correctly and a short wait is acceptable. Use UDP when a late packet is worth nothing.
Check your understanding
Why is TCP usually slower than UDP?
Worked example
A 1,000-packet file is sent with TCP. On the first try, 3 packets are lost.
- The receiver collects 997 packets and sends acknowledgements for them.
- For the 3 missing packets, no acknowledgements go back.
- After the wait, the sender sends those 3 packets again. This time they arrive.
- The receiver now has all 1,000, sorts them by number, and the file is complete.
The download took a little longer because of the 3 resends, but the file is perfect. With UDP, the same file would have 3 holes, and a program with holes would probably not work.
Common mistakes
- "TCP stops packets from being lost." No. Packets can still be lost on the way. TCP notices and sends them again.
- "TCP makes all packets take the same route." No. Packets can still take different routes. TCP puts them in order at the end.
- "TCP is always better than UDP." No. For a live call, TCP's waiting would make the call lag.
- "An acknowledgement carries the data." No. It is only a short receipt that says what arrived.
On the exam
TCP means reliable delivery: numbering, acknowledgements, resending and reordering, at the cost of some speed. If a question needs complete and correct data, such as a download or an email with an attachment, pick TCP. If it needs low delay, pick UDP.
Key words
TCP (Transmission Control Protocol): a protocol that makes delivery reliable by numbering packets, checking for acknowledgements and resending lost packets.
Acknowledgement: a short message from the receiver that says a packet arrived.
Reliable: sure to deliver all the data, correctly and in order.