diff --git a/app/src/main/java/com/ouxuan/oxface/device/OxUDP.java b/app/src/main/java/com/ouxuan/oxface/device/OxUDP.java index 0ba22d9..ad36585 100644 --- a/app/src/main/java/com/ouxuan/oxface/device/OxUDP.java +++ b/app/src/main/java/com/ouxuan/oxface/device/OxUDP.java @@ -302,8 +302,24 @@ public class OxUDP { // Log.d(TAG, "收到UDP响应: " + response); return response; + } catch (java.io.IOException e) { + Log.e(TAG, "发送UDP命令失败: " + command, e); + + // 特别处理网络不可达错误 + String errorMessage = e.getMessage(); + if (errorMessage != null && errorMessage.contains("ENETUNREACH")) { + String networkError = "网络不可达,请检查网络连接和设备IP地址(" + UDP_IP + ")是否正确\n错误详情: sendto failed: ENETUNREACH (Network is unreachable)"; + Log.w(TAG, "网络连接失败: " + networkError); + notifyUDPError(networkError); + } else { + // 其他网络错误 + notifyUDPError("UDP通信失败: " + errorMessage); + } + + return null; } catch (Exception e) { Log.e(TAG, "发送UDP命令失败: " + command, e); + notifyUDPError("UDP命令发送异常: " + e.getMessage()); return null; } finally { if (socket != null && !socket.isClosed()) {