打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
How to keep a XMPP connection stable on Android with (a)smack?

Actually There is not any problem with Reconnection manager. First you need to add connection listener to your connection manager.

connection.addConnectionListener(new ConnectionListener() {                    @Override                    public void reconnectionSuccessful() {                        Log.i("","Successfully reconnected to the XMPP server.");                    }                    @Override                    public void reconnectionFailed(Exception arg0) {                        Log.i("","Failed to reconnect to the XMPP server.");                    }                    @Override                    public void reconnectingIn(int seconds) {                        Log.i("","Reconnecting in " + seconds + " seconds.");                    }                    @Override                    public void connectionClosedOnError(Exception arg0) {                        Log.i("","Connection to XMPP server was lost.");                    }                    @Override                    public void connectionClosed() {                        Log.i("","XMPP connection was closed.");                    }                }); 

if any error occurred the connectionClosedOnError(Exception arg0) will automatically called when connection is closed

 public void connectionClosed() {                        Log.i("","XMPP connection was closed.");                        //You can manually call reconnection code if you                  want to reconnect on any connection close                    }

then check it this will call reconnectingin() method and try to reconnect.

Hope so this will help you.

use below code for check connection PingManager pingManager = PingManager.getInstanceFor(connection); pingManager.setPingInterval(5000);

add listner for ping fail handling to handle connection is connected or not because isConnected method is not reliable for check state of connection.

pingManager.registerPingFailedListener(PingFailedListener);

For mobile network connectivity is very big problem so you need to check network connectivity for mobile using broadcast receiver and on data reconnection you can use pingMyServer method to check connection is alive or not, if you are getting ping reply from server, means connection is alive otherwise on ping fail you can reconnect connection manually.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
基于XMPP协议的Android IM研究
mysql
键盘控制小球
Android studio 简单的音乐播放器实现
记录和恢复ListView滚动的位置
基于讯飞开放平台的安卓语音开发
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服