CLOSE
Updated on 12 Aug, 20259 mins read 4 views

Once the TCP three-way handshake is complete, the connection enters the data transfer phase.

Here, the main goal is to send and receive data reliably, in order, and without loss or corruption.

TCP achieves this through:

  • Segmentation of data
  • Sequence number
  • Acknowledgments
  • Flow control
  • Error detection and retransmission
  • Congestion control

TCP Segments and Structure

When an application sends data (e.g., a web browser requesting a page), TCP doesn't just throw the whole thing into the network. It breaks it down into segments.

Each TCP segments contains two main parts:

  1. Header – control information, like sequence numbers and flags.
  2. Data – the actual payload from the application.

Key TCP Header Fields for Data Transfer:

  • Source Port / Destination Port – Identify which application on each device is sending/receiving.
  • Sequence Number – identifies the position of the first byte of data in this segment.
  • Acknowledgment Number – tells the sender which byte the receiver expects next.
  • Flags – control bits like ACK, PSH, URG, etc.
  • Window Size – how much data can be sent before waiting for acknowledgment.
  • Checksum – error detection for data integrity.

Sequence Number and Acknowledgments

Sequence Number:

  • Every byte sent over TCP has a number.
  • This allows the receiver to reorder data if packets arrive out of order.

Acknowledgments:

  • When a receiver gets data, it sends back an ACK with the next expected sequence number.
  • Example: If you receive bytes 0-999, you send an ACK with Ack Number = 1000.

Why this matters:

Without sequence numbers, TCP couldn't reorder data or detect missing packets.

Flow Control (The Sliding Window)

Flow control prevents the sender from overwhelming the receiver.

How it works:

  • Receiver tells sender its window size – how many bytes it can receive before it needs to process more.
  • Sender can send only up to that limit before waiting for an acknowledgement.

This is known as the Sliding Window Protocol, because as ACKs arrives, the “window” moves forward, allowing more data to be sent.

Error Detection and Recovery

TCP uses a checksum to detect data corruption:

  1. Sender calculates a checksum for each segment.
  2. Receiver recalculates it on arrival.
  3. If they don't match, the segment is discarded, and the sender retransmits.

If a packet is lost, the sender will:

  • Detect it via missing acknowledgment.
  • Retransmits after a timeout (or earlier using fast retransmit if duplicate ACKs are received).

Congestion Control Basics

While flow control deals with receiver speed, congestion control deals with network speed.

TCP uses algorithms to:

  • Detect congestion (packet loss, delays).
  • Reduce sending rate when the network is busy.
  • Slowly increase speed when the network clears up.

Example of TCP congestion control algorithms:

  • Slow Start
  • Congestion Avoidance
  • Fast Retransmit
  • Fast Recovery

Leave a comment

Your email address will not be published. Required fields are marked *