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 1361042f..d048c800 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 @@ -250,21 +250,30 @@ public class RtkClusterService implements ApplicationRunner { } if (n > 0 && isLikelyText(probe, n)) { - if (!isSocketAlive(outConn)) { + Socket previous = outConn; + if (!isSocketAlive(previous)) { outConn = s; assigned = true; LOGGER.debug("Endpoint {} OUT connected", port); pumpOut(s, probe, n); } else { - LOGGER.info("Endpoint {} additional OUT connection detected; keeping existing", port); + LOGGER.info("Endpoint {} replacing existing OUT connection", port); + closeQuietly(previous); + outConn = s; + assigned = true; + pumpOut(s, probe, n); } } else { - if (!isSocketAlive(inConn)) { + Socket previous = inConn; + if (!isSocketAlive(previous)) { inConn = s; assigned = true; LOGGER.debug("Endpoint {} IN connected", port); } else { - LOGGER.info("Endpoint {} additional IN connection detected; keeping existing", port); + LOGGER.info("Endpoint {} replacing existing IN connection", port); + closeQuietly(previous); + inConn = s; + assigned = true; } } } catch (IOException e) {