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