0
這裏是我的代碼,我要使用它的ipv6地址連接到谷歌,但socket.connect()方法最後是拋出超時異常,我需要一些解決方案這一點,我應該在哪裏更改我的代碼,Socket.connect()方法失敗的ipv6地址
Uri google = new Uri("http://www.google.com");
IPAddress[] ips = Dns.GetHostEntry(google.DnsSafeHost).AddressList;
IPAddress ipAddress = ips[0];
foreach (IPAddress ip in ips)
{
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
ipAddress = ip;
}
IPEndPoint endPoint = new IPEndPoint(ipAddress, 80);
Socket socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 60 * 1000);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 60 * 1000);
socket.Connect(endPoint);
我必須要連接到它的ipv6地址,而不是ipv4 – hsCode
它對IP4地址工作正常嗎?只是想知道,如果您將InterNetworkV6更改爲InterNetwork,那麼工作是否正常。 –
是它使用ipv4地址 – hsCode