首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >连接wifi热点电话错误: ENETUNREACH

连接wifi热点电话错误: ENETUNREACH
EN

Stack Overflow用户
提问于 2014-12-02 12:08:51
回答 1查看 1.3K关注 0票数 3

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

代码语言:javascript
运行
复制
            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());
            }

我得到了下面的错误:

代码语言:javascript
运行
复制
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?因为我pinged了192.168.43.1,热点电话回应了。

EN

回答 1

Stack Overflow用户

发布于 2015-12-25 10:11:05

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

更改套接字的通信方式。

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

Android connect to tethering socket

这可能会有帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27241719

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档