I have written a simple network engine for client-server communication. It works perfectly on Windows, server knows when the client disconnected etc. (readLine() throws exception). I tried to port the engine to Android and sending and receiving data works, but for some reason server does not detect when the socket is closed (readLine() is still blocked and does not throw any exception). I even tried disconnecting the Android device from internet and it still did not detect closed socket. I thought of a workaround by implementing timeout, when the client does not send something for a long time, server will think that he is disconnected, but that's probably not a good permanent solution.
Code is surrounded by try-catch exception:
String userInput;
BufferedReader stdIn = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while ((userInput = stdIn.readLine()) != null) {
//do something
}