Pulsars
0 %
Log inSign up

From the domain name to the TCP connection

The TCP protocol and establishing a connection

TCP (Transmission Control Protocol) is the transport-layer protocol that guarantees reliable and ordered delivery of data, unlike UDP which offers no guarantee but is faster. Before exchanging any data, two machines using TCP must first establish a connection - this is the famous three-way handshake.

Each machine chooses an initial sequence number, which is used to track the order of the bytes sent and to detect losses or duplications. The connection is set up as follows:

Client                                   Server

  ---- SYN (seq=100) ------------------->     (1. proposes a sequence number)
  <--- SYN-ACK (seq=300, ack=101) -------      (2. accepts + proposes its own number)
  ---- ACK (seq=101, ack=301) ----------->     (3. confirms, connection established)

  ============ TCP data exchange ==============  (connection open in both directions)

The detail of the three segments:

  1. The client sends a SYN segment with its initial sequence number (here seq=100): it proposes to start a connection.
  2. The server replies with a SYN-ACK segment: it acknowledges (ack=101, i.e. the client's seq plus one) and in turn proposes its own sequence number (seq=300).
  3. The client replies with an ACK segment (ack=301): it confirms having received the server's number. The connection is then established in both directions.

Once the three segments have been exchanged, the two machines send data to each other while constantly confirming its correct reception. If a segment is lost, the sender does not receive an acknowledgement in time and retransmits it automatically.

Common pitfall: believing that the handshake already exchanges application data. In reality, the first three segments generally contain no data: they only serve to synchronise the sequence numbers of both sides.

Another pitfall: forgetting that closing a TCP connection is different from opening it. Closing typically uses four segments (FIN then ACK on each side), because each direction of communication must be closed independently - a detail often omitted in simplified diagrams.