Lessons in this course (12)

4. TCP vs UDP and the TLS handshake (HTTPS)

Intermediate★ Must knowLesson 4 of 12
TCPUDP
ConnectionYes — three-way handshakeNo — just send datagrams
ReliabilityAcknowledgements, retransmission, orderingNone — packets may be lost/reordered
Flow/congestion controlYesNo (app decides)
Overhead / latencyHigherLower
Used byHTTP/1.1, HTTP/2, SQL Server (TDS), SMTP, SSHDNS, video calls, gaming, streaming, QUIC (HTTP/3)

TCP three-way handshake: client SYN → server SYN-ACK → client ACK (one round trip before any data). Closing: FIN/ACK exchange; the closing side keeps TIME_WAIT for a while — why creating a new HttpClient per request can exhaust ports.

TLS 1.3 handshake (simplified, one round trip):

  1. Client Hello — supported ciphers, key share, SNI (which hostname it wants).
  2. Server Hello — chosen cipher, its key share, certificate, signature.
  3. Client verifies the certificate: issued by a trusted CA (chain to a root in the OS/browser store), not expired, hostname matches, not revoked.
  4. Both derive the same session keys (Diffie-Hellman) → encrypted HTTP flows.

HTTPS gives confidentiality (encryption), integrity (no tampering) and authentication (you're talking to the real shop.com). It does not make the application itself secure.

Certificates: DV (domain validated — Let's Encrypt, free, 90 days), OV/EV (organisation checks). Wildcard *.shop.com; SAN certificates list several names. Private key must stay secret on the server/Key Vault.