本文介绍了UDP-可选校验和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我对UDP的了解,它没有错误处理,没有检查发送/接收的数据序列,没有检查重复的数据包,没有检查损坏的数据包,并且显然不能保证所发送的数据包是均匀的收到...

From what I have read about UDP, it has no error handling, no checking for things like sequence of data sent/recieved, no checking for duplicate packets, no checking for corrupt packets and obviously no guarantee that the packets sent are even received...

因此,请记住,为什么实际上在UDP中存在使用校验和的选项?因为如果您确实要确保以正确的顺序接收到发送的数据(并且没有损坏等等),那么您将使用TCP ...

So with that in mind, why an earth is there actually an option to use checksums in UDP?? Because surely if you want to make sure the data being sent is received in the correct order (and not corrupt and so on) then you would use TCP...

感谢您的时间:)

推荐答案

UDP数据包包括一个16位CRC校验和的字段,接收操作系统将使用该字段来检查数据包是否损坏.如果校验和存在且失败,则该数据包将被静默丢弃.由应用程序决定是否发现数据包消失并采取纠正措施.

UDP packets include a field for a 16 bit CRC checksum which the receiving operating system will use to check for packet corruption. If the checksum is present and fails, then the packet will be silently discarded. It is up to the application to notice that the packet disappeared and take corrective action.

UDP校验和在所有现代操作系统上均默认启用.可以在套接字或操作系统级别禁用IPv4中的UDP校验和.这样做将减少在发送者和接收者处处理每个数据包的CPU开销.例如,如果应用程序正在分别计算其自己的校验和,则这可能是理想的.没有任何校验和,就无法保证接收到的字节与发送的字节相同.

UDP checksums are enabled by default on all modern operating systems. It is possible to disable UDP checksums in IPv4, either at the socket or OS level. Doing so would reduce the CPU overhead of processing each packet at both the sender and receiver. This might be desirable if, for example, the application were calculating its own checksum separately. Without any checksum, there would be no guarantee that the bytes received are the same as the bytes sent.

这篇关于UDP-可选校验和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:48