BufferedReader inBuffer=null;
try {
//从客户端读取数据
while (FActive) {
  inBuffer = new BufferedReader(new InputStreamReader(FSocket
          .getInputStream()));

  System.out.print(FSocket.getInetAddress()+":"+FSocket.getPort()+"  ");
  System.out.println(inBuffer.readLine());

}
inBuffer.close();
} catch (IOException e) {
  e.printStackTrace();
  System.out.println(e);
}
}客户端发送数据
while (true) {
  line = new BufferedReader(new InputStreamReader(System.in));
  if (null != line.readLine()) {
     out.println(line.readLine());
    if (line.readLine().equals("quit")) {
System.out.println("退出");
break;
   }
}
}本来应该是客户端输入,然后后回车,服务器端就收到,可现在是客户端输入多次,多次回车后服务器端才能收到一个。为什么?????

解决方案 »

  1.   

    不合适的地方很多,指出一处错误:
    if (null != line.readLine()) {
    out.println(line.readLine());
    if (line.readLine().equals("quit")) {
    应该这样:
    String str = line.readLine();
    out.println(str);
    if (str.equals("quit")) {
      

  2.   

    FActive,这个什么用处?服务器端socket对象应该一直处于阻塞状态,accept(),接收客户端发送的消息,可是我在你的代码中没有看到这个过程。
      

  3.   

    Factive 指当前是是打开还是关闭,服务器端的代码是已经得到一个客户端连接FSocket后进行循环检查FSocket是否有数据发来的代码。
      

  4.   

    晕,是我犯错了。先做了一个例子client.jva ,写了一个批处理用来编译和运行。又正式写了一个JClientSocket.java 
    但是忘记将批处理中的名称改过来了。所以写的代码和运行的根本就不是一个东西。改正这个错误后都正常了。