How to detect in the server that the client has closed the socket? When the client dies accidently the server goes in an infinite loop.

Krzysztof Raciniewski

The BufferedReader.read method returns -1 if the end of stream is reached (if your socket is closed). You should check your character for -1 and end the loop.