Computer Networks

TCP (Transmission Control Protocol)

Easy
10 min

What is TCP?

TCP (Transmission Control Protocol) is a communications protocol that operates at the transport layer of the Internet. Its purpose is to enable reliable data transfer between computers over a network. TCP is based on a connection-oriented and reliable service model, which ensures data integrity, order of arrival, and error-free transmission.

TCP protocol works on the following principle:

  • Connection establishment: The sending and receiving parties go through a three-step connection establishment process before sending actual data. This process ensures the readiness of both parties for data transmission and creates a connection between them.
  • Data segmentation: The information to be sent is divided into smaller parts or segments, each with a fixed size. This enables efficient data transfer over the network.
  • Segment numbering: Each segment is assigned its own number, which helps the recipient organize the segments in the correct order and identify any missing or erroneous segments.
  • Error detection and recovery mechanisms: TCP uses checksum verification to ensure the integrity of segments. If the receiver detects an error, it requests the sender to retransmit the faulty or missing segments. This ensures reliable transmission of data.

Establishing and terminating connections

The process of establishing and terminating a TCP protocol connection follows strictly defined stages, ensuring seamless communication between the parties. The following discusses the three-step connection establishment process and the four-step termination process of TCP.

Connection establishment

  • Step 1: The sender (client) sends a SYN (synchronize) message to the receiver (server), indicating their desire to establish a connection.
  • Step 2: The receiver responds with a SYN ACK (synchronize acknowledge) message, which confirms the receipt of the SYN message and indicates a willingness to continue the connection establishment.
  • Step 3: The sender sends an ACK (acknowledge) message to the recipient, who confirms the receipt of the SYN ACK message. This message indicates a successful connection establishment, and now data transmission can begin.

Disconnecting

  • Step 1: The sender sends a FIN (finish) message to express the desire to terminate the connection.
  • Step 2: The recipient responds with an ACK message to confirm receiving the FIN message.
  • Step 3: The recipient sends their own FIN message to indicate their desire to terminate the connection.
  • Step 4: The sender responds with an ACK message confirming the received FIN message.
  • Disconnection is now complete, and the connection is closed.

The TCP connection establishment and termination processes ensure that data transfer can occur reliably and securely. Each phase ensures that both the sender and receiver are aware of the connection status and each other's intentions. This enhances data integrity and ensures that connection resources are properly released after termination.

Data segmentation and numbering

The TCP protocol divides the transmitted data into smaller parts, called segments, which allows for efficient data transfer through the network. Each segment also receives a number, which helps the receiver to arrange the segments in the correct order and identify any missing or erroneous segments.

Data segmentation:

  • The data to be sent is divided into segments in the TCP protocol, each with a fixed size.
  • Segmentation helps in efficient data transfer over the network, as it allows the transfer of data in smaller parts that can be handled easier by network elements and routing.

Segment numbering:

  • Each segment in TCP protocol is assigned its own number, which identifies the segment.
  • With numbering, the receiver is able to organize the segments in the correct order as they arrive at their destination.
  • Numbering also allows detection of possible missing or erroneous segments and requesting retransmissions.

Segmentation and numbering are key features of the TCP protocol that help ensure the reliable transmission of data over the network. The use of segments enables efficient data processing and management of network congestion. Numbering ensures that segments are ordered correctly at the receiving end and that data arrives in the correct form without gaps or errors.

Error detection and recovery mechanisms

TCP protocol includes efficient error detection and recovery mechanisms that ensure data integrity and reliable transmission. With these mechanisms, TCP can detect and correct errors during data transfer.

Error detection:

  • TCP uses checksum to verify the integrity of segments.
  • The sending party calculates a checksum for each segment, based on the data contained in the segment.
  • The receiving party compares the checksum of the received segment to the checksum calculated by the sending party. If the sums do not match, the segment is considered erroneous.

Recovery mechanisms:

  • If the receiving party detects an error in the segment, it sends an ACK message to the sending party, which requests retransmission of the faulty or missing segment.
  • The sending party receives an ACK message and resends the requested segment.
  • In addition, the TCP protocol includes mechanisms for buffering and congestion control, which help ensure smooth data transmission over the network and prevent data loss or congestion.

The error detection and recovery mechanisms of TCP make it an extremely reliable protocol for data transmission. If a segment does not arrive at its destination or an error is detected, TCP requests retransmission to ensure that the data is transferred correctly. This guarantees data integrity and reliable transmission over the network.

Signals

TCP protocol uses multiple control signals:

SYN (Synchronize)

  • SYN signal is used in the initial phase of connection establishment.
  • The sender sends a SYN packet to the recipient to initiate a request for connection.

ACK (Acknowledge)

  • The ACK signal is used to confirm the reception of received data.
  • The recipient sends an ACK packet to the sender to indicate that the information has been successfully received.

FIN (Finnish)

  • FIN signal is used to terminate the connection.
  • The sender sends a FIN packet to the recipient to express their desire to terminate the connection.

RST (Reset)

  • The RST signal is sent when an error occurs in the connection or the connection cannot be continued.
  • The RST packet resets the connection and restores it to its initial state.

SYN-ACK (Synchronize Acknowledge)

  • The SYN-ACK signal is used to respond to the SYN signal and confirm the connection establishment request.
  • The receiver sends a SYN-ACK packet to the sender to express the willingness to continue the connection establishment.

PSH (Push)

  • PSH signal is used to indicate to the receiver that the data should be immediately delivered to the application instead of being buffered.

URG (Urgent)

  • The URG flag is used to indicate that the packet contains important or urgent data.
  • This signal can trigger the receiver to react quickly to urgent data processing.

Test Your Knowledge

What is the purpose of the TCP protocol?

What are the TCP connection establishment steps?

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.