这是我的代码,我将使用其ipv6地址连接到谷歌,但socket.connect()方法最后是抛出超时异常,我需要一些解决方案,我应该在哪里更改我的代码,< / p>
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);
答案 0 :(得分:0)
那么,您确定要连接到有效且在线且能够连接的IP地址吗? 超时并不意味着IPv6存在问题。