Ports
A port number picks the program; five values name the conversation
A port picks the program. Protocol, source and destination address and port form the 5-tuple that names each conversation.
An IP address gets a packet to the right machine. A port number gets it to the right program on that machine. The web server listens on TCP port four four three. The laptop opens two tabs to it. Each connection gets its own temporary source port, fifty-one two three four and fifty-one two three five, so the replies never get mixed up. A name lookup goes to the DNS resolver on UDP port fifty-three. TCP and UDP keep separate sets of ports.
Ports · Going deeper
Port ranges and the sockets on a machine
Well-known ports run 0–1,023; clients borrow ephemeral ports, 49,152–65,535 on Windows and 32,768–60,999 on Linux.
Handshake
TCP spends one round trip agreeing to talk
The three-way handshake, SYN, SYN-ACK, ACK, costs one round trip: on a 40 ms path the request leaves at 40 ms.
Before TCP sends any data, both sides agree to talk. The client sends a SYN, carrying the number its byte count will start from. The server answers with SYN-ACK: its own starting number, and an acknowledgement of the client’s. The client acknowledges, and can send its request in the same packet. On a 40 millisecond path, that is 40 milliseconds gone before the request even leaves, and the reply starts at 80.
Handshake · Going deeper
Closing a connection and the TCP states
Each side closes with FIN; RST aborts. The closer waits in TIME-WAIT so stray packets die out.
Reliability
TCP numbers every byte, so it resends exactly what was lost
The acknowledgement number is the next byte expected. Three duplicate ACKs trigger a fast retransmit of sequence 1,461.
TCP counts bytes, not packets. The server sends a segment starting at byte one, 1,460 bytes long. The client acknowledges 1,461: the next byte it wants. The second segment is lost on the way. The third, fourth and fifth arrive, but the client still wants byte 1,461, so it repeats that acknowledgement three times. Three duplicates tell the server something is missing. It resends just that segment, and one acknowledgement, 7,301, confirms everything.
Reliability · Going deeper · 1 of 3
Segment size and the options agreed at the start
The MSS is 1,460 bytes on Ethernet: the 1,500-byte MTU minus IP and TCP headers. SACK and window scaling are agreed in the SYN.
Reliability · Going deeper · 2 of 3
Throughput can never beat the window divided by the round trip
Throughput ≤ window ÷ round trip: 65,535 bytes over 100 ms is 5.2 Mbps. Window scaling lifts the limit.
The receiver tells the sender how much it can accept, the window. The sender can have that much data unacknowledged, then it must wait. With a 65,535-byte window and one millisecond round trip, that still allows over five hundred megabits a second. Ten milliseconds: fifty-two. Forty milliseconds: thirteen. A hundred milliseconds, across an ocean: about five, on a gigabit link. The fix is window scaling, agreed in the handshake, which lets the window grow to fill the path.
Reliability · Going deeper · 3 of 3
Congestion control: probe, back off, probe again
Slow start doubles the congestion window each round trip; a loss halves it, then it grows by one segment per round trip.
UDP
UDP sends and forgets, so it is quick and light
UDP has no handshake, acknowledgement or resend and an 8-byte header; DNS, DHCP, NTP, SNMP, voice and QUIC use it.
UDP is the opposite choice. Its header is eight bytes: ports, length and checksum. There is no handshake, so a DNS question and answer take one round trip, 40 milliseconds, instead of two. DNS, DHCP, time, network monitoring and live voice all use it. So does QUIC, which rebuilds the reliability of TCP inside the application and carries HTTP three.
UDP · Going deeper · 1 of 3
TCP and UDP side by side
TCP gives an ordered, complete byte stream; UDP gives separate datagrams, best effort, with multicast and broadcast.
UDP · Going deeper · 2 of 3
Live voice cannot wait for a resend
A G.711 call sends 200-byte packets 50 times a second, 80 kbps. Voice needs under 150 ms latency, 30 ms jitter, 1% packet loss.
A phone call shows why UDP exists. Every twenty milliseconds the phone sends a slice of sound: 160 bytes of audio and 40 bytes of headers, 80 kilobits a second. They leave evenly but arrive unevenly; that unevenness is jitter. The receiving phone holds a short buffer to smooth it out. One packet is lost. Resending it would take a round trip, far too late, so the phone just plays on. So the network must keep delay, jitter and loss low.
UDP · Going deeper · 3 of 3
Quality of service: mark, queue, shape
QoS marks packets with DSCP (voice is EF, 46), queues each class separately and polices or shapes at rate limits.
Lesson complete
You finished “TCP and UDP”
Nicely done.