From ec7f1b8ea93dbd8698e9888cb7fbdc25b783a649 Mon Sep 17 00:00:00 2001 From: yarnom Date: Tue, 28 Oct 2025 14:30:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=99=8D=E4=BD=8E=E8=B6=85=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sideslope/rtkcluster/RtkClusterService.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 1cd2594a..afcd96dc 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 @@ -204,17 +204,20 @@ public class RtkClusterService implements ApplicationRunner { private void classifyConnection(Socket s) { exec.submit(() -> { try { + // short probe to classify role s.setSoTimeout(300); InputStream in = s.getInputStream(); - byte[] probe = new byte[64]; + byte[] probe = new byte[256]; int n = 0; try { n = in.read(probe); } catch (IOException ignore) {} + // restore to blocking mode for steady-state + s.setSoTimeout(0); if (n > 0 && isLikelyText(probe, n)) { // OUT connection (NMEA etc.) closeQuietly(outConn); outConn = s; LOGGER.info("Endpoint {} OUT connected", port); - pumpOut(outConn); + pumpOut(outConn, probe, n); } else { // IN connection (RTCM sink) closeQuietly(inConn); @@ -237,11 +240,16 @@ public class RtkClusterService implements ApplicationRunner { return printable >= Math.max(1, n - 4); // tolerate some non-printables } - private void pumpOut(Socket s) { + private void pumpOut(Socket s, byte[] firstBuf, int firstLen) { exec.submit(() -> { try (InputStream in = s.getInputStream()) { byte[] buf = new byte[2048]; int read; + // deliver first classified bytes if any + if (firstLen > 0) { + String preview = new String(firstBuf, 0, Math.min(firstLen, 64), StandardCharsets.US_ASCII).replaceAll("\n", "\\n"); + LOGGER.info("[OUT:{}] {} bytes: {}...", port, firstLen, preview); + } while ((read = in.read(buf)) != -1) { // For now, just log a short preview String preview = new String(buf, 0, Math.min(read, 64), StandardCharsets.US_ASCII).replaceAll("\n", "\\n");