该函数Dns.GetHostEntry
不ipaddresses
作为字符串处理,例如127.0.0.1
,但如果我作为参数传递google.de
,它工作得很好。
难道我做错了什么 ?
public static Socket connSock(string Server, int Port)
{
Socket s = null;
IPHostEntry ipHE = Dns.GetHostEntry(Server);
//IPAddress[] ipA = null;
IPEndPoint ipE = null;
foreach (IPAddress address in ipHE.AddressList)
{
ipE = new IPEndPoint(address, Port);
Socket tempSocket = new Socket(ipE.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipE);
if (tempSocket.Connected)
{
s = tempSocket;
break;
}
else
{
continue;
}
}
return s;
}