开发者

Trying a UdpClient example from MS and getting an error. Why?

开发者 https://www.devze.com 2023-04-05 13:03 出处:网络
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.

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: "开发者_Python百科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


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消