UDP封包遗失 [英] UDP Packet loss

查看:257
本文介绍了UDP封包遗失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个大问题:
我正在从微型计算机向PC发送UDP pkt.
在我发送的pkt中,有一个计数器.我以100 Hz的频率发送了1Kb pkt.
当我从计算机收到pkt时,我会丢失一些pkt.我发现这是因为每次收到一个计数器时我都会增加一个计数器,而这个数字与我发送的计数器不同.这种差异不断增加.
有人有什么问题吗?我该怎么解决?
我的操作系统是Windows XP,使用的是Visual C ++ 2010 Express.
我用于接收pkt的函数是recvfrom.

Hi,
I''ve a big problem:
i''m sending UDP pkt from a micro to a pc.
In the pkt I send there is a counter. I send 1Kbyte pkt at 100 Hz.
When I receive the pkt from the pc I lose some pkt. I see that because I increase a counter every time I receive one of them and this number is different from the counter I send. this difference increase ever.
Have anyone the some problem? How can I solve it?
My OS is Windows XP and I''m using Visual C++ 2010 Express.
The function I''m using for receive the pkt is recvfrom.

推荐答案

来自^ ]):

UDP 使用简单的传输模型,而不使用隐式的握手对话来保证可靠性,排序或数据完整性.因此, UDP 提供的服务不可靠,并且 数据报可能会乱序到达,出现重复或丢失而不会发出通知 . UDP 假定不需要或不需要在应用程序中执行错误检查和纠正,从而避免了在网络接口级别进行此类处理的开销.对时间敏感的应用程序通常使用 UDP ,因为丢弃数据包比等待延迟的数据包更可取,这在实时系统中可能不是一个选择.如果在网络接口级别需要纠错功能,则应用程序可以使用为此目的而设计的传输控制协议(TCP)或流控制传输协议(SCTP).

请注意, Windows 系统通常无法确保 I/O延迟小于几毫秒,对于标准应用程序,必须将100 Hz视为持续频率.

该做什么在很大程度上取决于您的要求;您可以:


  • 使您的应用程序具有容错能力:只有在允许丢失一些数据报的情况下,这才可能实现
  • 更改传输协议,例如更改为 TCP/IP :这需要在您的微型计算机上实现更复杂的协议,则取决于它的资源和所使用的平台(请参阅 CMX Systems,Inc [ ^ ]例如 TCP /IP 实现8、16和32位micro)
  • Windows 使用实时扩展,例如 Ardence RTX (请参见 IntervalZero-RTX [
From User Datagram Protocol[^]):

UDP uses a simple transmission model without implicit hand-shaking dialogues for guaranteeing reliability, ordering, or data integrity. Thus, UDP provides an unreliable service and datagrams may arrive out of order, appear duplicated, or go missing without notice. UDP assumes that error checking and correction is either not necessary or performed in the application, avoiding the overhead of such processing at the network interface level. Time-sensitive applications often use UDP because dropping packets is preferable to waiting for delayed packets, which may not be an option in a real-time system. If error correction facilities are needed at the network interface level, an application may use the Transmission Control Protocol (TCP) or Stream Control Transmission Protocol (SCTP) which are designed for this purpose.

Be aware that Windows systems usually are not able to ensure I/O latencies smaller than some milliseconds, and 100 Hz has to be considered a sustained frequency for standard applications.

What to do is highly dependant on your requirements; you can:


  • make your application fault tolerant: this is possible only if it is acceptable to loose some datagram
  • change the transmission protocol, for instance to TCP/IP: this requires to implement a more complicated protocol on your micro, then it depends on its resources and on the platform that you use on it (see CMX Systems, Inc[^] for an example of TCP/IP implementation for 8, 16 and 32-bit micro)
  • use real-time extensions for Windows, like Ardence RTX (see IntervalZero - RTX[^]): this way you are able to write Windows applications with strict timing behaviours, and probably you will be able to work with UDP packets without problems


这篇关于UDP封包遗失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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