How to detect a remote side socket close? [duplicate]
The isConnected method won’t help, it will return true even if the remote side has closed the socket. Try this: public class MyServer { public static final int PORT = 12345; public static void main(String[] args) throws IOException, InterruptedException { ServerSocket ss = ServerSocketFactory.getDefault().createServerSocket(PORT); Socket s = ss.accept(); Thread.sleep(5000); ss.close(); s.close(); } } public class … Read more