在本地发送和接收UDP会丢失大量数据包 [英] Sending and Receiving UDP locally misses a lot of packets

查看:654
本文介绍了在本地发送和接收UDP会丢失大量数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用.NET Framework 2.0在VS2010中使用一个小程序,该程序旨在访问以这种方式与用户通信的设备。我写了另一个小程序来记录练习请求。所以我的客户端程序向
发送命令"设备模拟器"。它发回一个ACK,导致我的客户程序用另一个命令询问状态,最终它返回"完成"状态。来自模拟器的UDP消息然后再次发送其原始命令,这次它获得了一个有效的
响应及其想要填写的数据。

I'm working with a little program in VS2010 with .NET Framework 2.0 which is designed to access a device which communicates with a user that way. I wrote another little program that fields the requests for practice. So my client program sends a command to the "device simulator" which sends back an ACK which causes my client program to ask for status with another command and eventually it gets back a "done" UDP message from the simulator and then sends its original command again and this time it gets a valid response with the data it wants filled in.

好的,所以它有效,但是我必须真正编写它,以便在UDP数据包没有到达时再次重新发送每个命令或确认(在模拟器的情况下)。我知道UDP不保证到达并且它应该是不可靠的,但是当我在同一台机器上运行
这两个进程时,我无法完成协议的单次运行而至少没有几次重传。

Ok, so it works, but I had to really write it so that it would resend every command or ack (in the case of the simulator) again if the UDP packet didn't arrive. I know that UDP doesn't guarantee arrival and it's supposed to be unreliable, but when I run these two processes on my same machine, I can't get through a single run of the protocol without at least a few retransmissions.

请注意,我没有使用广播,我正在发送到特定的IP地址和套接字(或localhost和套接字),我正在使用相同的套接字双方传输和接收。问题是 - 这是正常的吗?当你在
之间的localhost下运行同一个Windows机器上的两个进程时,通常最终不得不在两个进程之间重新传输或者我做错了什么?

Note that I'm not using broadcast, I'm sending to a specific IP address and socket (or localhost and the socket) and I'm using that same socket to transmit and receive on both sides. The question is -- Is this normal? When you run under localhost between two processes on the same Windows machine is it normal to end up having to retransmit a lot between the two processes or am I doing something wrong?

谢谢。

洛克希德·马丁

推荐答案

这听起来有些不对劲。  您可能有一个路由循环,如果服务器/路由器看到重复的数据包,它可能会被丢弃。 我会开始尝试使用PING /?并使用主机IP地址(而非多播地址)测试一些选项。

It sound like something is wrong.  You may have a routing loop and if a duplicate packet is seen by a server/router it may be dropped.  I would start with trying to use PING/? and test some of the options using Host IP address (not multicast address).

如果您在接收端使用wireshark来监控流量,您应检查TTL号以查看跳数使用的数据包。  TTL号设置为发送器和转发器通过服务器/路由器的吞吐时间,数字减少
乘以1. 当TTL达到0时,服务器/路由器将丢弃该消息。 所以你没有在发射机上设置足够高的TTL,一些信息就会掉线。

If you use wireshark on the receive end to monitor traffic you should check the TTL number to see how many hops the packet used.  The TTL number is set a the tranmitter and evver time the messagge goes through a server/router the number is decreased by 1.  When the TTL reaches 0 the server/router will dropp the message.  So it you aren't setting the TTL high enough at the transmitter some message will be dropped.


这篇关于在本地发送和接收UDP会丢失大量数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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