package socket;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
//想要知道浏览器在访问服务器的时候给服务器发的什么。
public class ServerTom {
public static void main(String[] args) throws IOException {
System.out.println(InetAddress.getLocalHost().getHostAddress());
ServerSocket ss=new ServerSocket(1080);
Socket s=ss.accept();
byte[] arr=new byte[10247];
int num=s.getInputStream().read(arr);
PrintWriter ps=new PrintWriter
("C:\\Users\\Administrator\\Desktop\\代码总结\\浏览器.txt");
ps.print(new String(arr,0,num));
PrintWriter pw=new PrintWriter(s.getOutputStream(),true);
pw.println("客户您好啊");
System.out.println();
pw.flush();//打印流不是有自动刷新功能吗?
//s.close();//为何必须关闭网络输出流,或者在println后要flush(),浏览器才能收到数据???
ss.close();pw.close();
}
|