TCP (Transmission Control Protocol) uses a 3-ways handshake (aka TCP-handshake, 3-message handshake, and/or SYN-SYN-ACK) to setup a TCP/IP connection over an IP based network.

The three message mechanism is designed so that 2 computers that want to pass information back and forth to each other can negotiate the parameters of the connection before transmitting data such as HTTP browser requests.

  1. The initiator, generally the browser, sends a TCP SYNchronize packet to the other host (server)
  2. The server receives the SYN and sends back a SYNchronize-ACKnowledgement.
  3. The initiator receives the server’s SYN-ACK and sends an ACKnowledge. The server receives ACK and the TCP socket connection is established.

This handshake step happens after a DNS lookup and before the TLS handshake, when creating a secure connection.

The connection can be terminated independently by each side of the connection via a 4-way handshake

  • The initiator sends a FIN packet to the other host
  • The other host sends an ACK packet back to the initiator
  • Now the connection is half-closed, and the other host can still send data.
  • The other host sends a FIN packet to the initiator
  • The initiator sends an ACK packet back to the other host.

Context

  • Understanding latency