Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java readLine()从不停止阅读_Java_Readline - Fatal编程技术网

Java readLine()从不停止阅读

Java readLine()从不停止阅读,java,readline,Java,Readline,inforomclientr.readLine()永不停止。有什么想法吗?我忘了什么吗 服务器: /*{ some code: send a file with a dataoutputstream to client using a new port(4000) and when transfer is done i want a responce message (e.g. OK) send back to server in the old port(6000) }*/ Se

inforomclientr.readLine()
永不停止。有什么想法吗?我忘了什么吗

服务器:

/*{ some code:
    send a file with a dataoutputstream to client using a new port(4000) and when transfer is done i want a responce message (e.g. OK) send back to server in the old port(6000)  
}*/
 ServerSocket listenTransferSocket = new ServerSocket(6000);
      Socket connectionTransferSocket = listenTransferSocket.accept();

    BufferedReader inFromClientR =
             new BufferedReader(new InputStreamReader(connectionTransferSocket.getInputStream()));

     System.out.println("Client's response to Transfer: " +inFromClientR.readLine());
客户:

/*{ some code: 
receive the file on port (4000) and then the responce is sent to server using the following commands
}*/
Socket fileTransferSocket = new Socket("localhost", 6000);

 DataOutputStream outToServerR = 
       new DataOutputStream(fileTransferSocket.getOutputStream()); 

        outToServerR.writeBytes("Transfer completed " +'\n');
BufferedReader#readLine()尝试用8192字节填充其缓冲区,同时不重新添加它找到的任何换行符。由于您已打开连接,因此接收方将等待1)您已发送8192字节,或2)关闭连接


您最好使用其他一些帧机制,可能是ObjectOutputStream/ObjectInputStream。

在写入“传输完成”消息后,是否在客户端OutToServer.writeBytes(“传输完成”+“\n”)中刷新流;永不停止。该行后面的println从不显示为什么要将换行符与
字符串
分开附加?如果只执行
outtoserver.writeBytes(“传输完成”\n),会发生什么?您等待了多少时间?请尝试使用
writeChars
方法。
String line = null;
while ((line = inFromClientR.readLine()) != null) {
   // do sth
}