尝试 MS 的 UdpClient 示例并收到错误。为什么?
我正在尝试让我的程序的两个实例在它们之间进行通信。我被提到了 udp,所以我尝试从这里运行示例: http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient%28v=VS.100%29.aspx 但我收到一个错误: “socketException (0x80004005):这通常是主机名解析期间的临时错误...”
如何解决此问题?
我对这些东西一无所知。我用谷歌搜索了我需要的内容,找到了这个 此处:
//This is how you do it (kudos to sipwiz)
UdpClient udpServer = new UdpClient(localpt); //This is what the proprietary(see question) sender would do (nothing special)
//!!! The following 3 lines is what the poster needs...(and the definition of localpt (of course))
UdpClient udpServer2 = new UdpClient();
udpServer2.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
udpServer2.Client.Bind(localpt);
谢谢
I’m trying to get two instances of my program to communicate between them. I’ve been referred to udp, and so I’m trying to run the example from here: http://msdn.microsoft.com/en-us/library/system.net.sockets.udpclient%28v=VS.100%29.aspx
But I get an error:
"socketexception (0x80004005): This is usually a temporary error during hostname resolution..."
how do I solve this?
I don’t know anything about this stuff. I googled for what I needed and found this here:
//This is how you do it (kudos to sipwiz)
UdpClient udpServer = new UdpClient(localpt); //This is what the proprietary(see question) sender would do (nothing special)
//!!! The following 3 lines is what the poster needs...(and the definition of localpt (of course))
UdpClient udpServer2 = new UdpClient();
udpServer2.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
udpServer2.Client.Bind(localpt);
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是您正在使用未经修改的示例代码。
这是尝试连接到不存在的
AlternateHostMachineName
,因此抛出0x80004005: No such host isknown
异常。您需要修改代码才能连接到真实服务器。
The issue is you are using the code for the sample unmodified.
This is trying to connect to
AlternateHostMachineName
which does not exist, and therefore throws a0x80004005: No such host is known
exception.You need to amend the code to connect to a real server.
原因是您引用的主机名无法解析和/或您的网络设置(尤其是 DNS)在某种程度上是错误的...
您引用的示例包含两个主机名
www.contoso.com< /code> 和
AlternateHostMachineName
- 两者都无法解析,因为它们不存在...您需要将它们替换为真实的主机名或 IP 地址,并确保您的 DNS 设置正确/有效。 。The reason is that you are refering to hostnames that can't be resolved and/or your network settings (esp. DNS) are are somehow wrong...
The example you refer to contains two hostnames
www.contoso.com
andAlternateHostMachineName
- both are not resolvable since they don't exist... you need to replace them with real hostnames or IP adresses and make sure that your DNS settings are correct/working...