diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/connection/SocketConnection.java b/clientserver/src/main/java/net/rptools/clientserver/simple/connection/SocketConnection.java index 674429eb24..42124691c5 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/connection/SocketConnection.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/connection/SocketConnection.java @@ -16,6 +16,7 @@ import java.io.*; import java.net.Socket; +import java.net.SocketTimeoutException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -161,6 +162,9 @@ public void run() { try { byte[] message = SocketConnection.this.readMessage(in); SocketConnection.this.dispatchCompressedMessage(message); + } catch (SocketTimeoutException e) { + log.warn("Lost client {}", SocketConnection.this.getId(), e); + return; } catch (IOException e) { log.error(e); return; diff --git a/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java b/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java index 47f2a95fcb..2b4c0ac9c5 100644 --- a/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java +++ b/clientserver/src/main/java/net/rptools/clientserver/simple/server/SocketServer.java @@ -17,6 +17,7 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; +import java.util.concurrent.TimeUnit; import net.rptools.clientserver.simple.connection.SocketConnection; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -103,6 +104,9 @@ public void run() { while (!stopRequested) { try { Socket s = socket.accept(); + // Client heartbeat frequency is 20 seconds, so a minute should permit two or three + // heartbeats to come in if still connected. + s.setSoTimeout((int) TimeUnit.MILLISECONDS.convert(1, TimeUnit.MINUTES)); log.debug("Client connecting ..."); String id = nextClientId(s);