- 建立服务端需要监听一个端口
- ServerSocket ss = new ServerSocket(9999);
- Socket s = ss.accept ();
- InputStream in = s.getInputStream();
- byte[] buf = new byte[1024];
- int num = in.read(buf);
- String str = new String(buf,0,num);
- System.out.println(s.getInetAddress().toString()+”:”+str);
- s.close();
- ss.close();
复制代码
请问,为什么上面代码中int num = in.read(buf);不需要用while循环读取信息呢,它那样不就是读一次没读完就不执行了吗? |
|