简体   繁体   English

数据包损坏和UDP

[英]Packet corruption and UDP

I have to simulate a client server UDP relationship by uploading files from the client to the server. 我必须通过将文件从客户端上传到服务器来模拟客户端服务器UDP关系。 It also uses a stop and wait protocol. 它还使用停止和等待协议。 My question is do I need to have code in my server class to handle corrupt packets? 我的问题是我是否需要在服务器类中包含代码来处理损坏的数据包? I read somewhere online that a ** 我在网上某处读到一个**

UDP packet with a checksum error will be rejected by the stack. 带有校验和错误的UDP数据包将被堆栈拒绝。 In other words, it's not possible for a UDP packet with a checksum error to be "received at the other end correctly", because the packet will not be received at all. 换句话说,带有校验和错误的UDP数据包不可能“在另一端正确接收”,因为根本不会接收到该数据包。

** **

Is that true? 真的吗? Would by server simply not receive the packet resulting in my client having a packet timeout? 服务器会不会仅仅接收不到导致我的客户端发生数据包超时的数据包?

UDP is a lossy protocol, it does not guarantee delivery of data. UDP是一种有损协议,它不能保证数据传输。 I imagine your simulation of a client server UDP relationship is a "best effort" (emulating the protocol itself) and so no, you would not need this extra code. 我想您对客户端服务器UDP关系的模拟是“尽力而为”(模拟协议本身),所以不,您不需要此额外的代码。

I have read in many text books that some stack implimentations will provide a packet w/ an error indicating the checksum has failed while others discard the packet. 我读过许多教科书,其中一些堆栈实现将提供一个带有错误的数据包,该错误指示校验和失败,而其他错误则丢弃该数据包。 In practice all of the systems I have ever used discard the packet if the checksum fails. 实际上,如果校验和失败,我曾经使用过的所有系统都将丢弃该数据包。

If the packet is indeed dropped then the timeout + resend will suffice. 如果确实丢弃了数据包,则超时+重发就足够了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM