TCP (Transmission Control Protocol)
What it is for
UDP adds only ports and leaves the rest to the application: nobody replaces a lost packet, reorders anything, or slows a sender down.
★★★ TCP takes on all three. The price is that both ends keep state per connection, the header grows from 8 bytes to 20 or more, and a round and a half of handshaking happens before any data moves.
Why the handshake is three-way
★★★ Because each side's sequence number must be acknowledged by the other:
· A sends SYN with its initial sequence number -> B learns A's;
· B replies SYN+ACK carrying its own and acknowledging A's -> A now knows both;
· A acknowledges once more -> only now does B know its own number arrived.
★★ Two exchanges leave B's number unconfirmed; a fourth would be redundant.
★ Common misconceptions
★★★ "TCP guarantees delivery" -- what it guarantees is that you will be told when it cannot deliver. Unplug the cable and it has no magic left.
★★★ "TCP is slower than UDP" -- equally fast on a clean link. The difference shows up under loss: TCP stops to repair, UDP charges on.
★★ "An ACK means the peer's application read the data" -- an ACK only means the kernel accepted it; the application may not have read it yet.