RecapDifficulty: Intermediate1 min

Recap: Ports, TCP and UDP

A port reaches the program, and the transport is chosen by what a late packet costs.

The transport layer gets data from a machine to a program, and it offers two different promises.

  • A port names one program's endpoint on a host. Servers listen on well-known ports; clients use ephemeral ones.
  • Five values, the protocol, both addresses and both ports, identify a connection. No two live connections share all five.
  • UDP sends datagrams with no connection, no retransmission and no order, in an eight-byte header.
  • TCP delivers a complete, ordered stream of bytes, at the cost of a handshake and of waiting for lost data.
  • The choice turns on what a late packet is worth: wait for it with TCP, or carry on without it with UDP.
  • Refused means a host answered and nothing listens on the port; timed out means nothing answered.
TCP and UDP on the three properties that decide between them
PropertyTCPUDP
Lost dataSent againStays lost
OrderGuaranteedNot guaranteed
CostA handshake and waiting behind a lossNone; the application handles gaps