jok*_*efe 2 c# microsoft-metro windows-8 windows-runtime .net-4.5
我正在将WP7应用程序移植到Windows 8 Metro,我遇到的一个(很多)转换障碍是发现基于主机名或DNS名称的IP地址.以下是我之前在WP7中使用的示例:
DnsEndPoint dnsEnd = new DnsEndPoint("www.google.com", 80, AddressFamily.InterNetwork);
DeviceNetworkInformation.ResolveHostNameAsync(dnsEnd, IPLookupCallbackMethod, this);
Run Code Online (Sandbox Code Playgroud)
我在网上搜索了一个解决方案并浏览了Metro API,但我还没有找到任何东西.有没有其他人遇到Metro/WinRT这个问题并找到了解决方案?
using Windows.Networking;
using Windows.Networking.Sockets;
HostName serverHost = new HostName("www.google.com");
StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();
// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");
// Now try the clientSocket.Information property
// e.g. clientSocket.Information.RemoteAddress
// to get the ip address
Run Code Online (Sandbox Code Playgroud)
一旦clientSocket尝试连接,clientSocket.Information属性将被包含大量网络信息,包括远程主机信息(包括ip地址).我只是输入内联,所以我希望没有错误.希望这可以帮助!也可以尝试这个链接到msdn.