diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java index 35a16fbb..9e711c6d 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/rtkcluster/RtkClusterService.java @@ -256,6 +256,21 @@ public class RtkClusterService implements ApplicationRunner { } // IN should not be the same socket as OUT if (inConn == s) inConn = null; + // Try minimal handshake if this looks like an HTTP/NTRIP GET from RTKLIB, + // to keep the connection open when rtkrcv mistakenly uses ntripcli. + try { + String head = new String(buf, 0, Math.min(read, 256), StandardCharsets.US_ASCII); + if (head.startsWith("GET ") || head.contains("RTKLIB/")) { + OutputStream os = s.getOutputStream(); + String resp = head.contains("HTTP") + ? "HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n" + : "ICY 200 OK\r\n\r\n"; + os.write(resp.getBytes(StandardCharsets.US_ASCII)); + os.flush(); + LOGGER.info("[OUT:{}] handshake responded: {}", port, resp.trim()); + } + } catch (Exception ignore) {} + LOGGER.info("Endpoint {} OUT established", port); } String preview = new String(buf, 0, read, StandardCharsets.US_ASCII).replaceAll("\n", "\\n"); LOGGER.info("[OUT:{}] {}", port, preview); @@ -264,7 +279,10 @@ public class RtkClusterService implements ApplicationRunner { LOGGER.debug("Connection reader closed on {}: {}", port, e.getMessage()); } finally { liveConns.remove(s); - if (outConn == s) outConn = null; + if (outConn == s) { + outConn = null; + LOGGER.info("Endpoint {} OUT disconnected", port); + } if (inConn == s) inConn = null; closeQuietly(s); ensureInCandidate();