Detecting Socket disconnect

573 Views Asked by At

I've a Socket connected to another device on my LAN. How can i detect the disconnection When i unplug the device from the AC. The thread is blocked on:

BufferedReader b=//
b.readLine();
1

There are 1 best solutions below

0
On

If you're going to use such logic, then set a timeout on the socket (i.e. setSoTimeout(TIMEOUT_IN_MILLISECONDS)). This will interrupt the blocking I/O operation.