java - 直接写入socket,获取TCP ZeroWindow

标签 java sockets tcp window

如你所见,我直接每10秒向特定套接字发送一个请求(以保持存活和检测),但它只能发送两次。使用wireshark,发现我发送的第三个包有TCP ZeroWindow,无法发送到服务器。以下软件包也是如此。通常,Window Size 应该保持在正常水平,而不是一直减小。源代码有什么问题?任何帮助表示赞赏!

我得到了三个包:

The First Package The Second Package The Third Package

源码:非常简单

public class pediy {

    public static void main(String[] args) throws IOException {

        URL url = new URL("http://bbs.pediy.com");
        Socket socket = null;
        PrintWriter os = null;
        BufferedReader is = null;

        while(true) {

            socket = new Socket(url.getHost(), 80);
            os = new PrintWriter(socket.getOutputStream());

            String request = "GET / HTTP/1.1\nHost: bbs.pediy.com\nProxy-Connection: keep-alive\nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\nUser-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17 CoolNovo/2.0.6.12\nAccept-Encoding: gzip,deflate,sdch\nAccept-Language: en-US;q=0.6,en;q=0.4\nAccept-Charset: utf-8;q=0.7,*;q=0.3\n";
            try {
                while (true) {

                    os.println(request);
                    os.flush();

                    System.out.println("Finished");
                    Thread.sleep(1000*10);
                }

            } catch (Exception e) {
                System.out.println("Error" + e);
            } finally {
                CloseAll(socket, os);
            }
        }
    }

    private static void CloseAll(Socket socket, PrintWriter os) throws IOException {
        if(socket != null) socket.close();
        if(os != null) os.close();
    }
}

最佳答案

这仅仅意味着 TCP 连接的另一端没有使用(读取)您发送的数据,因此 TCP 流量控制启动以减慢发送者的速度。

关于java - 直接写入socket,获取TCP ZeroWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824786/

相关文章:

python - TypeError : a bytes-like object is required, 不是 'str'

sockets - 客户端和服务器的不同套接字缓冲区大小

javascript - 相当于 : echo 'message' | nc -v <server> <port> 的 Node.js

java - 如何使用 sed 或 awk 编辑很长的 Java 类

java - Spring boot 2.0.5.RELEASE 应用程序未部署在 JBoss 6.4.0 中

java - 支柱2 : Displays table of Songs - null gets printed

java - 文件的内存扫描,最好使用 ClamAV

c# - 如何在 2500 多个套接字上实现 TCP/IP 心跳?

java - 使用套接字从 HTTP Post 接收数据

python - socket.getfqdn() 和 socket.gethostname() 在使用 socket.gethostname 时给出不同的 IP 地址