Server端程序:
package com.test22;import java.io.*;
import java.net.*;public class Test06_server {
public static void main(String[] args) throws IOException {
 ServerSocket ss=new ServerSocket(10000);
 Socket s=ss.accept();
 InputStream is=s.getInputStream();
 byte[] buf=new byte[1024];
 int len=0;
 len=is.read(buf);
 String str1=new String(buf,0,len);
 System.out.println(str1);
//  while((len=is.read(buf))!=-1){
//  System.out.println();
//  String str1=new String(buf,0,len);
//  System.out.println(str1);
//  }
 OutputStream os=s.getOutputStream();
 String str2="server send message";
 os.write(str2.getBytes());
 s.close();
 ss.close();
}
}
Client端程序:
package com.test22;import java.io.*;
import java.net.*;public class Test06_client {
public static void main(String[] args) throws UnknownHostException,
IOException {
 Socket s=new Socket("127.0.0.1", 10000);
 OutputStream os=s.getOutputStream();
 String str1="client send message";
 os.write(str1.getBytes());
 InputStream is=s.getInputStream();
 byte[] buf=new byte[1024];
 int len=0;
 while((len=is.read(buf))!=-1){
 String str2=new String(buf,0,len);
 System.out.println(str2);
 }
 s.close();
}
}我的问题是:我在server端,使用while()循环的代码来接收客户端的消息会出现阻塞的问题,我但是client端使用while()却没有问题,我想问下是什么原因啊?求java高手回复