用Socket连接Http端口的延时问题
大家好:
我写了这样一段程序连接某个服务器的80端口;
public static void main(String[] args) throws Exception{
Socket socket = new Socket("server",80);
String data = "GET index.html HTTP/1.1\r\n\r\n";
socket.getOutputStream().write(data.getBytes(),0,data.length());
socket.getOutputStream().flush();
Date d = new Date();
System.out.println(d.toString());
StringBuffer sb = new StringBuffer();
while(socket.getInputStream().available()==0);
int c;
while ((c = socket.getInputStream().read()) != -1)
sb.append((char) c);
System.out.println(sb.toString());
d = new Date();
System.out.println(d.toString());
System.out.println("done");
}
结果服务器隔了三分钟才有response,但是如果用windows自带的telnet连接上去,
打"GET index.html HTTP/1.1"接两个回车,则马上就有response显示出来。
请问这个延迟问题应该怎么解决?多谢帮助!