下面的程序模拟客户端接收Tomcat发来的数据,为什么eclipse控制台没有输出信息呢??

package cn.david.net.test;

import java.io.*;
import java.net.*;
public class MyBrowser {

/**
* @param args
*/
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
browser();
}

public static void browser() throws IOException{
Socket s = new Socket("192.168.0.100",8080);
PrintWriter out = new PrintWriter(s.getOutputStream(),true);
out.println("GET /MyWeb/testDemo.html HTTP/1.1 ");
out.println("Accept: */* ");
out.println("Host: 192.168.0.100:8080");
out.println("Connection: close ");
out.println(" ");
out.println(" ");

InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = 0;
while((len=in.read(buf))!=-1){
String str = new String(buf,0,len);
System.out.println(str);
}
s.close();
}

}

out.write("GET /MyWeb/testDemo.html HTTP/1.1\r\n");
out.write("Host: 192.168.0.100\r\n");
out.write("Agent: whatever\r\n");
out.write("Connection: close\r\n");
out.write("\r\n");
out.flush();
你试下这样写应该可以的,你没加换行符
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答
大家正在搜