SocketException, connect reset by peer. Weird behaviour when heartbeating server

172 views Asked by At

Working on a client-server android application. The clients are polling the bufferedinputstream (in) for server messages, meanwhile also repeatedly checking if server is reachable so they can terminate instantly when server goes offline.

try {
while (true) {
    if (MainActivity.in.available() > 0) {
        message = MainActivity.readInput();
        break;
    }
    Thread.sleep(100);
}
} catch (IOException e) {Log.e("myoutput", e.toString()); serverOffline = true; } //server probably offline?
catch (InterruptedException e2) {}

On one of my test devices (android 2.2) this works as I thought, as soon as I close down the server the IOException is triggered. Although on my second test device (android 4.3) the IOException is not triggered (compling with API 8). But I'm starting to think this is not a device thing as I tried running both API 8 and 18 in the emulator and it didn't trigger.

Any ideas?

I'm probably not providing all essential information to get any help from here, please let me know if so and I'll provide!

0

There are 0 answers