1
Dns.GetHostEntry
함수는 ipaddresses
을 문자열로 처리하지 않습니다. 127.0.0.1
하지만 매개 변수로 google.de
을 전달하면 매우 잘 작동합니다.Dns.GetHostEntry가 IP를 포함하는 문자열을 변환하지 않습니다
내가 잘못 했나요?
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;
}
기대하는 바가 무엇이며 정확한 오류 메시지는 무엇입니까? 나에게'Dns.GetHostEntry ("127.0.0.1")'은 주소 목록 (ipv4와 ipv6)을 반환하지만'tempSocket.Connect (ipE)'는 throw합니다. –