TCP 和 UDP 如何检测传输错误? [英] How do TCP and UDP detect transmission errors?

查看:182
本文介绍了TCP 和 UDP 如何检测传输错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道这些协议如何检测数据传输过程中发生了错误?谢谢

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

推荐答案

可能会出现不同的错误:

There are different errors that can occur:

  • 数据包顺序不正确
  • 丢包
  • 数据包内的数据损坏
  • 幻象数据包(接收者收到从未发送过的数据包)

UDP 只提供了一种克服数据损坏的机制(这是 IPv4 中的一个可选功能,IPv6 中是强制性的).

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

数据损坏

UDP 仅能抵抗数据包内数据的损坏,前提是每个数据包的标头中都使用了校验和字段.基本上,它需要标头、数据包内容和更多信息(如 IP 地址),将其解释为补码中的 16 位字的长列表,并将它们总结起来 UDP 校验和.

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 有类似的方法来解决数据损坏问题.

TCP has a similar approach to tackle corruption of data.

所有其他问题

TCP 对每个数据包都有所谓的序列号.序列号寻址字节,因此如果发送方说这是序列号为 102 的数据包",他说,他发送的数据包以流的字节 102 开始.然后接收器向接收器发送和确认.例如,如果数据包的长度为 10 字节,则接收方将发送带有序列号 112 的 Ack,这意味着我希望接收的下一个数据包以序列号 112 开始".每个具有不同序列号的数据包要么是重复的(太低),要么是丢失的数据包(接收到的序列号太高),要么是幻像(预期序列号与接收到的序列号完全不匹配).因此,在所有序列号不匹配的情况下,接收方都知道出现问题并可以做出反应(与不同的 TCP 版本不同).

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).

发送方等待接收方的确认.如果他在一段时间内没有收到预期的 ack,他将重新传输数据包,因为他假设数据包在途中丢失了.

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 ;)

这篇关于TCP 和 UDP 如何检测传输错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆