Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-是谁的服务器提前关闭了连接,还是没有将整个响应发送到我的套接字?_C#_Sockets_Whois - Fatal编程技术网

C#-是谁的服务器提前关闭了连接,还是没有将整个响应发送到我的套接字?

C#-是谁的服务器提前关闭了连接,还是没有将整个响应发送到我的套接字?,c#,sockets,whois,C#,Sockets,Whois,我正在发送服务器172.217.2.142\r\n,它只响应: # #ARIN WHOIS数据和服务受使用条款约束 #可访问: # #如果您发现结果不准确,请在 # # 我的接收功能: private string getResponse(Socket sock) { byte[] buffer = new byte[1024]; string result = string.Empty; int bytesReceived = 0; do {

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

#
#ARIN WHOIS数据和服务受使用条款约束
#可访问:
#
#如果您发现结果不准确,请在
#
#

我的接收功能:

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;
}

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

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

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

出于好奇,为什么要使用像
Socket
这样的低级对象,而不是像
TcpClient
这样的高层抽象,或者使用
WebClient
和更新的Whois RWS API?没有具体原因,仅仅是一次学习经验。在这种情况下,“必须”是一个过于强烈的词,并且是一种限制。简单地说“一种流行的方式就是使用”<代码>网络客户端感谢您的更正,感谢我可怜的法语:)