TCP

1 minute read

TCP three-way handshake

The TCP handshake, also known as the TCP three-way handshake, is a method used by TCP (Transmission Control Protocol) to establish a connection between a client and a server.

It’s a fundamental process in networking that ensures both devices are ready to send and receive data before data transmission begins.

Here’s how it works:

SYN (Synchronize):

The process starts when a client (such as a web browser) sends a TCP packet with the SYN (Synchronize) flag set to the server.

This packet contains the client’s initial sequence number, which is a random number used to identify segments in the data stream.

SYN-ACK (Synchronize-Acknowledge):

Upon receiving the SYN packet, if the server is available and willing to communicate, it responds with a TCP packet that has both the SYN and ACK ( Acknowledgment) flags set.

The server also selects its own initial sequence number and includes it in this response.

ACK (Acknowledge):

Finally, the client responds to the server’s SYN-ACK packet by sending an ACK packet back.

This packet acknowledges the server’s sequence number, and both sides of the connection are now synchronized and ready to exchange data.

Key points about the TCP handshake:

Connection Establishment: The handshake establishes a reliable connection between the client and server, ensuring that both parties are aware of each other and are ready to transfer data.

Sequence Numbers: Each side of the connection selects an initial sequence number to number the bytes of data sent during the connection. This helps in tracking which data has been received and which hasn’t.

Acknowledgment: The ACK packets confirm the receipt of data and ensure reliable communication by retransmitting any data that isn’t acknowledged.

The TCP handshake is crucial for ensuring reliable, error-checked communication between devices over a network, forming the basis of many internet protocols like HTTP (for web browsing), FTP (file transfer), and more.