문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top