1

该函数Dns.GetHostEntryipaddresses作为字符串处理,例如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;
    }
4

1 回答 1

1

这可能意味着您的系统无法获取主机条目。当没有为给定 IP 定义 PTR 记录时,就会发生这种情况(例如)。

于 2012-11-25T15:18:54.287 回答