The way TCP establishes a connection is through the use of different TCP control flags used in a very specific order.

Source:

TCP 3-Way Handshake Process - GeeksforGeeks

TCP control flags

Untitled

Untitled

Handshake

A way for two devices to ensure that they’re speaking the same protocol and will be able to understand each other

After establishing a connection Computer A is free to send whatever data it wants to Computer B and vice versa.

Each segment sent in either direction should be responded to by a TCP segment with the ACK field sent. This way the other side always knows what has been received.

In order to close this connection we use the four-way handshake.