Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/393.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_Android_Ios_Sockets_Bufferedreader - Fatal编程技术网

java readLine()中的读取响应结束

java readLine()中的读取响应结束,java,android,ios,sockets,bufferedreader,Java,Android,Ios,Sockets,Bufferedreader,我正在线程中使用上述代码来接收套接字连接的响应。 在Android中,它可以正常工作,就像我使用out.println()发送数据一样,但当设备连接到ios并开始接收数据时,它无法识别终端,只有在连接关闭时才会接收到。除了readLine()以及如何在上述代码中使用之外,还有其他方法吗。这样会更好 try { input = new BufferedReader(new InputStreamReader(

我正在线程中使用上述代码来接收套接字连接的响应。

在Android中,它可以正常工作,就像我使用
out.println()
发送数据一样,但当设备连接到ios并开始接收数据时,它无法识别终端,只有在连接关闭时才会接收到。除了
readLine()
以及如何在上述代码中使用之外,还有其他方法吗。

这样会更好

    try {
                    input = new BufferedReader(new InputStreamReader(
                            mSocket.getInputStream()));
                    while (!Thread.currentThread().isInterrupted()) {
                        String messageStr = null;
                        messageStr = input.readLine();
                        if (messageStr != null) {
                            updateMessages(messageStr, false);
                        } else {
                            break;
                        }
                    }
                    input.close();
                } catch (IOException e) {
                    Log.e(CLIENT_TAG, "Server loop error: ", e);
                }
看一看,我想你会解决你的问题。
try 
{
    input = new BufferedReader(new InputStreamReader(mSocket.getInputStream()));
    String messageStr = "";
    while (!Thread.currentThread().isInterrupted() && (messageStr = input.readLine()) != null) 
    {
        updateMessages(messageStr, false);
    }
    input.close();
} catch (Exception e) {
     Log.e(CLIENT_TAG, "Server loop error: ", e);
}