UDPClient接收方法在IPEndPoint中返回0.0.0.0

编程入门 行业动态 更新时间:2024-10-15 08:25:21
本文介绍了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

本文发布于:2023-11-25 04:56:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1628418.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   UDPClient   IPEndPoint

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!