From b5d124abe5e69b258fd3ed38abfcd9b88cb5bebd Mon Sep 17 00:00:00 2001 From: zhy200308 <2258391712@qq.com> Date: Tue, 11 Aug 2026 21:26:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(android):=20=E7=BD=91=E5=85=B3=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B=E8=BF=87=E6=BB=A4=200.0.0.0=20=E7=AD=89=E6=97=A0?= =?UTF-8?q?=E6=95=88=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 实测诊断截图里出现了 http://0.0.0.0:39393 这个候选。它来自默认路由的 空网关(直连链路无下一跳),永远不可能连上,白白占用探测预算并把真正 的候选挤到后面。回环与组播地址同理,一并过滤。 --- android/app/src/main/java/com/qft/optical/WifiConnector.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/android/app/src/main/java/com/qft/optical/WifiConnector.kt b/android/app/src/main/java/com/qft/optical/WifiConnector.kt index 109cf9f..3915f47 100644 --- a/android/app/src/main/java/com/qft/optical/WifiConnector.kt +++ b/android/app/src/main/java/com/qft/optical/WifiConnector.kt @@ -339,6 +339,10 @@ class WifiConnector(context: Context) { return props.routes .asSequence() .mapNotNull { it.gateway as? Inet4Address } + // 默认路由的网关可能是 0.0.0.0(直连链路,无下一跳), + // 回环和组播地址也不可能是对端。全都探测一遍纯属浪费时间, + // 而且会把真正的候选挤到后面。 + .filterNot { it.isAnyLocalAddress || it.isLoopbackAddress || it.isMulticastAddress } .map { "http://${it.hostAddress}:$port" } .distinct() .toList()