For data to be sent across the Internet, traffic is sent over either TCP or UDP. This post will focus on how a TCP session is established, for more information on the differences between UDP and TCP click here.
In order for a TCP session to be established between 2 devices, a process known as the TCP 3 Way Handshake must occur.
How It Works
We know that TCP uses sequence numbers when sending packets, this is part of how the order of packets are verified, and a great way to identify any missing data that might have been lost in transit.
When it comes to the 3 Way Handshake, we have 3 types of communication occurring:
- Synchronise [SYN]
- Synchronise-Acknowledgement [SYN-ACK]
- Acknowledgement [ACK]
To put this into context, let’s say we have 2 devices, Host A and Host B. Host A is trying to establish a TCP connection with Host B.
Step 1:
Host A first sends a Synchronise Packet to Host B essentially signalling its intention to establish a TCP connection.
Step 2:
Host B receives the Synchronise Packet and sends its own Packet back Acknowledging it received the Synchronise Packet.
This is known as a SYN-ACK Packet.
Step 3:
Host A receives the SYN-ACK Packet and sends a final Acknowledgement Packet to confirm the SYN-ACK Packet was received successfully.
At this stage, the requirements to establish a TCP connection have been established and the to hosts may now communicate using TCP.