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