Transmission Control Protocol (TCP)

TCP is a more reliable, connection-based transport protocol compared to UDP. Its header is larger than UDP and all segments have sequence number. This allows TCP to reconstruct the correct order of packages. It can also ask for retransmission of a segment in case it is missing.

../../_images/tcp_segments.png

Establishing a TCP connection

Before any data is transmitted, the two hosts perform a so-called three-way handshake to initiate a connection.

  1. The client sends that it wants to establish a connection (SYN) and that it will use the attached sequence number

    ../../_images/tcp_handshake_0.png
  2. The server will respond with SYN and ACK bits set, returning its own sequence number

    ../../_images/tcp_handshake_1.png
  3. Finally the client acknowledges with ACK with its next sequence number

    ../../_images/tcp_handshake_2.png

Once a connection is established, each TCP segment is sent with the next sequence number.

../../_images/tcp_handshake_3.png

Note

The connection is closed in a similar way.

Error Correction

Given that each TCP segment has a sequence number and checksum, errors can be easily detected and corrected:

  1. any segment that is transmitted must be acknowledged by the other side

  2. if the sender does not receive an acknowledgment after a certain time, it assumes the segment was lost

  3. This causes the segment to be sent again

  4. the same happens if a segment checksum is invalid

    ../../_images/error_correction_0.png ../../_images/error_correction_1.png ../../_images/error_correction_2.png ../../_images/error_correction_3.png

Flow Control

TCP allows to detect if one side is sending data at a rate higher than what the receiver can handle. Or if there is congestion on the network and packages are dropped. TCP can slow down or increase the transmission rate to adjust to connectivity and traffic congestion. This is called flow control.

../../_images/flow_control.png