通而不达网络的发现与解决方案

网友投稿 850 2022-09-26

通而不达网络的发现与解决方案

通而不达网络的发现与解决方案

通而不达网络又称受限网络。若连接到这样的网络,手机收到的是网络正常通知,手机状态栏出现正常的wifi标志。若已经连接上后切换到这种网络,select函数监控不到异常(正常的响应超时,网络错误码errno有时间为45有时间为22,但是我们的socket在正常的情况下有时间errno为9,有时间为22,所以根据errno判断不出来这种异常),但是收不到服务器发回的所有响应(类似于 iphone手机里设置的弱网测试,丢失率为100%的设置情况)。在这种网络下发起connect 连接,那么会出现典型的75秒超时的情况。所以通而不达的网络典型特征是connect 75秒超时。通而不达网络通常是网络防火墙禁止了用户随意访问外网,进行了身份识别和登录。 既然网络通知,select函数, connect函数及网络错误码(errno)都不能准确定位出这类异常网络,那么解决这样的通而不达网络的办法代价很大,只能用心跳的方式发现这类网络。毕竟这类的网络很罕见,一般通过连接3次或超过75*2秒没有连接上,或没75秒发送一次心跳,若服务器无法实时响应(10秒)就判定它为通而不达网络。 aibinjiang这个网络在登录连接上切换到后台,到了无信号区自动切换到4g网络,后进入aibinjiang信号区,在次离开该信号区,自动切换到4g网络。在connect连接时1毫秒给予响应,结果为1(0为正常,非零为失败),返回的错误码是65(网关或主机不可达),53(软件引起的连接异常)。

连接aibinjiang公交wifi网络异常日志:

15/12/03 08:13:18:422 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1807 Debug:connect before:_connectTime = 1449101598421, Thread Sno: 182015/12/03 08:13:18:422 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1811 Debug:connect after:_connectTime = 1449101598422, Thread Sno: 182015/12/03 08:13:18:423 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2586 Debug:ret = 12015/12/03 08:13:18:423 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2598 Debug:pipe data:GuardThreadStartMonitor2015/12/03 08:13:18:423 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1865 Debug:errno:652015/12/03 08:13:18:423 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2613 Debug:收到守护线程开始监控的消息,开始实时监控长连接线程:GuardThreadStartMonitor2015/12/03 08:13:18:423 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1880 Debug:i= -12015/12/03 08:13:18:423 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1882 Debug:error : 652015/12/03 08:13:18:423 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2586 Debug:ret = 12015/12/03 08:13:18:424 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:2530 Debug:socket err 2015/12/03 08:13:18:424 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2598 Debug:pipe data:GuardThreadIdle2015/12/03 08:13:18:424 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:2549 Debug:sleep: 1秒2015/12/03 08:13:18:424 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2604 Debug:收到守护线程空闲的消息,停止实时监控长连接线程:GuardThreadIdle2015/12/03 08:13:19:372 Singleton.m:-[Singleton getLatitudeAll]:392 Debug:函数2015/12/03 08:13:19:372 Singleton.m:-[Singleton getLongitudeAll]:404 Debug:函数2015/12/03 08:13:19:372 Singleton.m:-[Singleton getLatitudeAll]:392 Debug:函数2015/12/03 08:13:19:372 Singleton.m:-[Singleton getLongitudeAll]:404 Debug:函数2015/12/03 08:13:19:372 Singleton.m:-[Singleton getDistanceWithStartLat:startLng:endLat:endLng:]:564 Debug:函数2015/12/03 08:13:19:489 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1650 Debug:SKIP fd= 192015/12/03 08:13:19:489 Singleton.m:-[Singleton getLoginOrderStat]:265 Debug:函数2015/12/03 08:13:19:489 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1735 Debug:socket sucess 2015/12/03 08:13:19:489 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1736 Debug:g_fd= 192015/12/03 08:13:19:489 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1741 Debug:main loop 2015/12/03 08:13:19:490 Singleton.m:-[Singleton getLoginOrderStat]:265 Debug:函数2015/12/03 08:13:19:490 SingleAsyncSocket.m:-[SingleAsyncSocket getNetworkStatus]:54 Debug:函数2015/12/03 08:13:19:490 SingleAsyncSocket.m:-[SingleAsyncSocket getNetworkStatus]:54 Debug:函数2015/12/03 08:13:19:490 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1807 Debug:connect before:_connectTime = 1449101599489, Thread Sno: 182015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2586 Debug:ret = 12015/12/03 08:13:19:492 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1811 Debug:connect after:_connectTime = 1449101599491, Thread Sno: 182015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2598 Debug:pipe data:GuardThreadStartMonitor2015/12/03 08:13:19:492 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1865 Debug:errno:652015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2613 Debug:收到守护线程开始监控的消息,开始实时监控长连接线程:GuardThreadStartMonitor2015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2586 Debug:ret = 12015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2598 Debug:pipe data:GuardThreadIdle2015/12/03 08:13:19:492 SingleAsyncSocket.m:__32-[SingleAsyncSocket guardThread]_block_invoke:2604 Debug:收到守护线程空闲的消息,停止实时监控长连接线程:GuardThreadIdle2015/12/03 08:13:19:492 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1880 Debug:i= -12015/12/03 08:13:19:492 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:1882 Debug:error : 652015/12/03 08:13:19:492 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:2530 Debug:socket err 2015/12/03 08:13:19:493 SingleAsyncSocket.m:__36-[SingleAsyncSocket socketBSDThread]_block_invoke:2549 Debug:sleep: 1秒

iphone手机弱设置(用来模拟测试应用在不通网络环境下的健壮性),在设置->开放者->Status(Network Link Condtioner)里设置。

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringBoot使用ip2region获取地理位置信息的方法
下一篇:Xcode8.1如何支持iOS8.0以下版本
相关文章

 发表评论

暂时没有评论,来抢沙发吧~