连接wifi热点电话错误:ENETUNREACH



我有一个应用程序,该应用程序使用热点连接两部手机以发送/接收文件。一部手机创建热点(Wifi热点),我使用以下代码连接另一部热点手机:

            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并且热点电话回复了。

我以前遇到过这个问题。 这对我有用。

更改套接字的通信方式。

尝试在连接到热点的客户端上打开服务器套接字,并在网络共享设备上创建客户端套接字以连接到服务器套接字。

安卓连接到网络共享套接字

这可能会有所帮助!!

最新更新