Java 连接wifi热点电话错误:ENETUNREACH
我有一个应用程序,该应用程序连接两个手机使用热点发送/接收文件。一部手机创建热点(Wifi热点),我使用以下代码连接另一部热点手机:Java 连接wifi热点电话错误:ENETUNREACH,java,android,android-wifi,Java,Android,Android Wifi,我有一个应用程序,该应用程序连接两个手机使用热点发送/接收文件。一部手机创建热点(Wifi热点),我使用以下代码连接另一部热点手机: mSocket = new Socket(); try { mSocket.setReuseAddress(true); mSocket.bind(null); mSocket.setPerformancePrefer
mSocket = new Socket();
try {
mSocket.setReuseAddress(true);
mSocket.bind(null);
mSocket.setPerformancePreferences(0, 1, 2);
mSocket.setTcpNoDelay(true);
mSocket.setSoLinger(true, 0);
mSocket.setKeepAlive(true);
mSocket.connect(new InetSocketAddress(mConnection.getServerAddress(),
mConnection.getServerPort()), SOCKET_CONNECT_TIMEOUT);
//operation here....
} catch (SocketException e) {
((HotSpotConnection)mConnection).getlocalip();
LogUtils.LOGE(LOG_TAG, "init exception:" + e.toString());
} catch (IOException e) {
LogUtils.LOGE(LOG_TAG, "init exception:" + e.toString());
}
我得到了以下错误:
E/MyTestWifiThread(18918): init exception:java.net.ConnectException:
failed to connect to /192.168.43.1 (port 9876) after 30000ms:
isConnected failed: ENETUNREACH (Network is unreachable)
为什么无法连接到热点电话,我确定热点电话地址默认为192.168.43.1?因为我ping了192.168.43.1,热点电话回复。我以前遇到过这个问题。这对我很有用 更改套接字的通信方式 尝试在连接到热点的客户端上打开服务器套接字,并在栓接设备上创建客户端套接字以连接到服务器套接字
这可能会有帮助 我今天也有同样的问题。对于这个问题有什么推荐调试方法吗?