C# - 为什么whois.arin.net提前关闭连接或者没有将整个响应发送到我的套接字?

时间:2016-04-19 17:42:01

标签: c# sockets whois

我发送服务器172.217.2.142\r\n,只响应:

  


   #ARIN WHOIS数据和服务受使用条款的约束    #available at:https://www.arin.net/whois_tou.html
   #
   #如果您发现结果不准确,请在
报告    #https://www.arin.net/public/whoisinaccuracy/index.xhtml
   #

我的接收功能:

private string getResponse(Socket sock)
{
    byte[] buffer = new byte[1024];
    string result = string.Empty;
    int bytesReceived = 0;

    do
    {
        bytesReceived = sock.Receive(buffer, 0, buffer.Length, SocketFlags.None);
        Debug.Print("Bytes read:" + bytesReceived.ToString());
        result += Encoding.ASCII.GetString(buffer);
        Array.Clear(buffer, 0, buffer.Length);
    } while (bytesReceived > 0);

    return result;
}

1 个答案:

答案 0 :(得分:1)

一种流行的方法是使用WebClient从URL加载数据:

using (WebClient client = new WebClient())
{
    string value = client.DownloadString("url");            
}

返回的值是arin.net的JSON格式。