Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do TCP and UDP detect transmission errors?

I want to know that how these protocols can detect that an error has been occurred during the data transmission? thanks

like image 333
user472221 Avatar asked Dec 25 '10 07:12

user472221


People also ask

What does TCP and UDP use to detect errors or data corruption?

Checksum is a simple error detection mechanism to determine the integrity of the data transmitted over a network. Communication protocols like TCP/IP/UDP implement this scheme in order to determine whether the received data is corrupted along the network.

How does TCP correct transmission errors?

Error detection and correction in TCP is achieved through the use of three simple tools: checksum, acknowledgment, and time-out. Checksum : Each segment includes a checksum field which is used to check for a corrupted segment.

How does UDP detect errors?

No error checking,error correction, or acknowledgment is done by UDP. UDP is only concerned with speed. So when, the data sent over the Internet is affected by collisions, and errors will be present.

Does TCP have error detection?

TCP provides reliable, ordered, and error-checked delivery of a stream of octets (bytes) between applications running on hosts communicating via an IP network.


3 Answers

There are different errors that can occur:

  • Incorrect order of the packets
  • Loss of packets
  • Corrupt data inside the packet
  • Phantom packets (receiver gets packets that have never been sent)

UDP only provides a mechanism to overcome the corruption of data (which is an optional feature in IPv4, mandatory in IPv6).

Corruption of Data

UDP is only resistant against the corruption of data inside packets, if the checksum field is used in the header of every packet. Basically it takes the header, the packet content and some more information (like IP addresses), interprets this as a long list of 16 bit words in ones-complement and sums them up UDP checksum.

TCP has a similar approach to tackle corruption of data.

All the other problems

TCP has so-called sequence numbers for every packet. The sequence number addresses bytes, so if the sender says "this is the packet with sequence number 102", he says, that the packet he sent starts with the byte 102 of the stream. The receiver then sends and acknowledgement to the receiver. For example, if the packet has a length of 10 bytes, the receiver will send and Ack with the sequence number 112, which means "i expect the next packet to be received to start with the sequence number 112". Every packet that has a different sequence number is either a duplicate (too low) or a packet got lost (received sequence number is too high) or it is a phantom (total mismatch of expected sequence number and received one). So in all cases of sequence-number mismatch, the receiver knows that something goes wrong and can react (differs from different TCP versions).

The sender waits for the acknowledgements of the receiver. If he does not receive an expected ack for a certain time, he will retransmit packets, because he assumes, that the packets got lost on their way.

This is only a very brief explanation. The topic is somewhat bigger than described here ;)

like image 70
Tobi Avatar answered Sep 21 '22 15:09

Tobi


At the IP protocol level (on which both UDP and TDP are based), there is a checksum that confirms that the contents of the packet are valid. However, there are situations where certain errors are not detected by this checksum.

Usually at a higher level (such as when transferring a file), there is a more robust hash calculated on the contents of the file. This might be done on the complete file, or on individual blocks of the file of some size (usually much larger than a single IP packet).

like image 32
Greg Hewgill Avatar answered Sep 21 '22 15:09

Greg Hewgill


If I recall from various classes, Greg was right with the checksum as one of a few sources of data verification. However, UDP (designed the way it is) is not always 100% reliable. This makes it perfect for streaming data (webcams, for example), as losing a frame is not that big a deal. While this would be considered an error in TCP (which would then have to resend the frame, delaying all following frames), UDP does not really care unless it is configured to.

Provided that all data is required to be received, the protocol in question on the requesting side makes sure to ask for each packet to be sent, typically in order. Checksum comes in to play here as each part is then checked to make sure it is correct (small problem when the data part errors an even number of times as the checksum can then throw a false positive, but this is pretty rare). Each time a part fails, it is re-requested until it is both received and checksum gives a thumbs up. As each part is received, the protocol at the receiver responds to the sender that everthing is cool. If the sender does not receive this response within some time limit, it resends the packet.

like image 24
Scott S Avatar answered Sep 22 '22 15:09

Scott S