S
S
sk1nny_puppy2014-08-20 11:31:25
Java
sk1nny_puppy, 2014-08-20 11:31:25

What to do on EOFException while reading from socket stream on android?

There is a class in android app that constantly reads something from ssl socket. Reading is done in a separate thread via DataInputStream.readFully.

From time to time, an EOFException is thrown while reading, with the socket itself saying isConnected() == true and isClosed() == false.

What is the correct way to handle these exceptions?

An example code to make it clearer what is at stake:

byte[] buf = new byte[1]{};
try {
    inputStream = new DataInputStream(s.getInputStream());
    while (!Thread.currentThread().isInterrupted()  && s.isConnected()) {
        inputStream.readFully(buf); // вот здесь кидается исключение
        // какая-то обработка этого всего
    }
}  catch (IOException e) {
    Log.e(LOG_TAG, "exception while reading: " + e);
    e.printStackTrace();
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sk1nny_puppy, 2014-08-20
@sk1nny_puppy

On SO, everyone is inclined to believe that this is because the server is dropping the connection, and, accordingly, you need to handle this exception by reconnecting to the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question