fix: 排查TCP SERVER 发布RTCM消息的断联问题

This commit is contained in:
yarnom 2025-10-29 11:46:45 +08:00
parent fb095ad52c
commit 3522e16070

View File

@ -256,6 +256,21 @@ public class RtkClusterService implements ApplicationRunner {
} }
// IN should not be the same socket as OUT // IN should not be the same socket as OUT
if (inConn == s) inConn = null; 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"); String preview = new String(buf, 0, read, StandardCharsets.US_ASCII).replaceAll("\n", "\\n");
LOGGER.info("[OUT:{}] {}", port, preview); LOGGER.info("[OUT:{}] {}", port, preview);
@ -264,7 +279,10 @@ public class RtkClusterService implements ApplicationRunner {
LOGGER.debug("Connection reader closed on {}: {}", port, e.getMessage()); LOGGER.debug("Connection reader closed on {}: {}", port, e.getMessage());
} finally { } finally {
liveConns.remove(s); liveConns.remove(s);
if (outConn == s) outConn = null; if (outConn == s) {
outConn = null;
LOGGER.info("Endpoint {} OUT disconnected", port);
}
if (inConn == s) inConn = null; if (inConn == s) inConn = null;
closeQuietly(s); closeQuietly(s);
ensureInCandidate(); ensureInCandidate();