smack connect to xmpp server with previous stream id

ぐ巨炮叔叔 提交于 2019-12-05 09:54:24

I think one of the following will solve your issue-

  • First check is mod_offline enabled in the server side.
  • If mod_offline enabled then check offline message limit in the server side. It should be greater than 0.
  • Use PingManager to stable your connection. I am here putting sample code to use PingManager in android-

During XMPPTcpConnection initiation-

pingManager = PingManager.getInstanceFor(this.connection);
pingManager.registerPingFailedListener(new PingFailedListener() {
    @Override
    public void pingFailed() {
        // session dropped, request for reconnection
    }
});

When XMPPTcpCOnnection authenticated-

@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
    configurePingManager();
}

private void configurePingManager() {
    pingManager.setPingInterval(ACCORDING_SERVER_PING_INTERVAL);
    pingManager.pingServerIfNecessary();
}
  • Make sure stream_management enabled both in server side and client side. I am here putting a sample code to enable stream_management for android client side-

xmppTcpConnection.setUseStreamManagement(true); xmppTcpConnection.setUseStreamManagementResumption(true);

When XMPPTcpCOnnection authenticated checking session status send and request all pending streams using the code below-

@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
    configurePingManager();
    if (!resumed) {
        try {
            xmppTcpConnection.sendSmAcknowledgement();
            xmppTcpConnection.requestSmAcknowledgement();
        } catch (SmackException.NotConnectedException | StreamManagementException.StreamManagementNotEnabledException e) {
            e.printStackTrace();
        } 
    }
}  

Hope following all those steps your problem will be solved.

after lots of searching ,finally i upgraded Ejabberd server to the latest version 17.03

where they've added the new module mod_stream_mgmt ,and changed the behavior of stream management , so when i create a new connection it get rebind to the old one and receive the unsent and un-handled messages

to activated the mod_stream_mgmt i used the following configurations :

mod_stream_mgmt : 
  resume_timeout :60
  resend_on_timeout: true

Note : I have also activated mod_ping on server side ,I don't know if that has a direct effect on this process and case but right now my clients are not missing any messages .

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!