The function Dns.GetHostEntry
doesn't handle ipaddresses
as strings e.g. 127.0.0.1
but if I pass google.de
as a parameter it works quite well.
Am I doing something wrong ?
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;
}
This could mean you're system is unable to get the host entry. This occurs (for instance) when there's no PTR record defined for the given IP.