尝试 MS 的 UdpClient 示例并收到错误。为什么?

发布于 2024-12-05 03:24:23 字数 1024 浏览 0 评论 0原文

我正在尝试让我的程序的两个实例在它们之间进行通信。我被提到了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你的他你的她 2024-12-12 03:24:23

问题是您正在使用未经修改的示例代码。

这是尝试连接到不存在的 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 a 0x80004005: No such host is known exception.

You need to amend the code to connect to a real server.

污味仙女 2024-12-12 03:24:23

原因是您引用的主机名无法解析和/或您的网络设置(尤其是 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 and AlternateHostMachineName - 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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文