先说问题吧,为什么我的ServerSocket自定义的服务器接有时接收得到,有时接收不到,浏览器发过来的消息呢?
- System.out.println(InetAddress.getLocalHost().getHostAddress());
- ServerSocket socket=new ServerSocket(11115);
- Socket s=socket.accept();
-
- InputStream is=s.getInputStream();
-
- byte[] b=new byte[1024];
- int len=is.read(b);
- System.out.println("长度"+len);
- System.out.println(new String(b,0,len));
- BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
-
- bw.write("<font color='red'>hello browser</font>");
- bw.flush();
- bw.close();
-
- s.close();
- socket.close();
复制代码
我的访问地址是:192.168.1.102:11115,它老报错,由于我接收到的len等于-1。大虾们,SOS!!!! |