askvity

How to Achieve Error Handling in TCP?

Published in TCP Error Handling 4 mins read

Error handling in TCP is primarily accomplished through a few key mechanisms to ensure reliable data transmission.

Key Error Handling Techniques in TCP

TCP uses specific techniques to identify and handle errors during data transfer. These techniques focus on detecting corrupted data and ensuring that lost data is retransmitted.

Checksum

The fundamental error detection method in TCP is the checksum.

  • How it Works: Each TCP segment includes a checksum field. This checksum is a calculated value based on the segment’s data.
  • Purpose: Upon arrival, the receiving TCP calculates its own checksum of the received segment. If this calculated checksum doesn't match the checksum in the segment's header, the segment is considered corrupted.
  • Action Taken: Corrupted segments are discarded by the receiving TCP and are considered lost, as the reference states: "Every segment contains a checksum field which is used to find corrupted segments. If the segment is corrupted, then that segment is discarded by the destination TCP and is considered lost."

Sequence Numbers

TCP assigns sequence numbers to each byte of data sent. This allows the receiver to identify if segments are missing, or received out of order.

  • How it Works: Sequence numbers are added to each segment which allows the receiving side to verify the order of arrival.
  • Purpose: Missing segments can be identified, meaning that some segments were lost.
  • Action Taken: When missing segments are detected, the receiver sends back acknowledgement messages (ACKs), sometimes including flags indicating what the expected sequence number is.

Acknowledgements (ACKs) and Retransmission

TCP uses acknowledgments to ensure reliable delivery of data.

  • How it Works: When a TCP segment is received successfully, the receiving TCP sends an acknowledgment (ACK) back to the sender. The ACK also indicates which sequence number is expected next.
  • Purpose: ACKs confirm receipt and delivery. If an ACK is not received within a certain time, it indicates a potential lost segment.
  • Action Taken: The sending TCP will retransmit the lost segment after a timeout.

Timeout and Retransmission

  • How it Works: TCP maintains a timer for each segment it sends. This timer expires if an acknowledgment is not received within a certain period, called a timeout.
  • Purpose: Timeouts determine when to retransmit segments.
  • Action Taken: When a timeout occurs, the sending TCP assumes the segment was lost and retransmits it.

Error Handling Process

The process involves these steps:

  1. Data Segmentation: The data is broken into segments.
  2. Checksum Calculation: A checksum is computed for each segment and added to the segment header.
  3. Transmission: The segment is transmitted.
  4. Reception and Checksum Verification: The receiving TCP calculates its own checksum and verifies it against the one included in the segment.
  5. Discarding Corrupted Segments: If the checksums do not match, the segment is discarded.
  6. Acknowledgement: The receiving TCP sends an ACK if the segment is received correctly.
  7. Retransmission or Timeout: If no ACK is received within a timeout period, the segment is retransmitted by the sending TCP.

Summary

Technique Function Action
Checksum Detects corrupted segments Discard corrupted segments
Sequence Numbers Verifies segment order and detects lost segments Request retransmission if a segment is out of order or missing.
Acknowledgments (ACKs) Confirms successful delivery of segments Trigger retransmissions when they're missing
Timeout and Retransmission Ensures retransmission of unacknowledged segments Retransmit segments when acknowledgements are not received in time

By using these methods, TCP achieves reliable data transmission by detecting and correcting errors.

Related Articles