我正在搜索System.Net.Sockets.AddressFamily.InterNetwork的替代品。我找到了HostName但无法找到像AdressFamily那样的东西。实际上,我正在转换winRT中的以下代码。我知道winRT支持Windows.Networking.Sockets等。请描述一些解决方案。 代码是,
if (System.Net.Sockets.AddressFamily.InterNetwork == _address.AddressFamily && _address.AddressFamily == address.AddressFamily)
{
long longLocal = BitConverter.ToInt32(_address.GetAddressBytes(), 0);
long longNetMask = BitConverter.ToInt32(_netmask.GetAddressBytes(), 0);
long longRemote = BitConverter.ToInt32(address.GetAddressBytes(), 0);
}
_address也是IPAdress
答案 0 :(得分:1)
好AddressFamily
并不直接支持WinRT / Metro项目,所以您需要检查ipAddress
这样的信息
using Windows.Networking;
using Windows.Networking.Sockets;
HostName serverHost = new HostName("www.contoso.com");
StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();
// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");
var ipAddress = clientSocket.Information.RemoteAddress.DisplayName
要检查您的情况,请使用_address.Type == HostNameType.Ipv4
然后执行某些操作,但请确保GetAddressBytes
类中不存在HostName
,因此您需要编写自己的函数来转换ipAddress
1}}到字节。