UDPClient接收方法在IPEndPoint中返回0.0.0.0 [英] UDPClient Receive method returns with 0.0.0.0 in the IPEndPoint

查看:295
本文介绍了UDPClient接收方法在IPEndPoint中返回0.0.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的(?)C#线程,它侦听UDP套接字并返回
基本信息,供任何要求的人使用.

我有一个不容易重复的错误(尽管它经常重复出现,但是
无法预料),因为收到了我收到的款项,我得到了例外,
处理它,但是当我使用Send方法时,结果发现
我从接收中获得的IPEndpoint具有空(0.0.0.0)IP地址.

这是.NET 3.5的版本.

该文档没有提及此选项,而只是说它
可能会抛出SocketException,但我没有看到它!


开始,该代码就不会对IPEndPoint进行任何操作 数据将一直接收到发送响应为止.

有人看到过这样的东西吗?

还是有人对导致这种情况的原因有任何想法?

我正在运行测试以尝试立即捕获它...

2011年9月8日星期二更新:

在对UDPClient.Receive(ref receivePoint)的调用之后,我添加了以下代码:

I have a simple (?) C# thread that listens on a UDP socket and returns
basic information to whoever asks for it.

I have a not-easily-repeatable error (although it recurs regularly, but
not predictably), where I get an exception because I take what I received,
process it, but when I get to the Send method, it turns out that the
IPEndpoint I got from Receive has a null (0.0.0.0) IP address.

This is for .NET 3.5.

The documentation does NOT mention this as an option, and only says that it
may throw a SocketException, which I catch, but have not seen!

The code does not "do" anything with the IPEndPoint from the time the
data is received until it sends the response.

Has anyone seen anything like this?

Or does anyone have any ideas about what would cause this?

I am running tests to try and capture it right now...

Tuesday 08/09/11 update:

I added the following code after the call to UDPClient.Receive(ref receivePoint):

if (receivePoint.Address.Equals(IPAddress.Parse("0.0.0.0")))
{
    log.ErrorOut("CollectorMonitor", "Got NULL IP Address from Receive()", Constants.ERROR_RECVD_NULL_IPADDRESS);
    continue;
}



我仍然有例外,但没有满足上述条件!但是,虽然
代码在调试器中,当我对该条件进行快速监视时,它显示为true!

现在,这是一个线程化的应用程序,其他线程使用TCPClient.可能有
那里发生某种奇怪的互动?


谢谢,

Mitch



I still got the exception, but it did NOT catch the condition above! However, while the
code was in the debugger, when I did a Quick watch on the condition, it showed as true!

Now, this is a threaded application, and the other threads use TCPClient. Could there be
some type of weird interaction going on there?


Thanks,

Mitch

推荐答案

很抱歉,但我从未遇到过,但是IPEndPoint需要什么呢?
为什么不简单地使用listner.acceptUdpClient返回的客户端对象?
并使用发送方法rathar而不是SendTo.

我不确定我是否清楚.
I am sorry, but I never faced this, but what would you need IPEndPoint for ?
Why don''t you simply use the client object returned by listner.acceptUdpClient ?
and use send method rathar than SendTo.

I am not sure I got things clear.


这篇关于UDPClient接收方法在IPEndPoint中返回0.0.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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