Smack connect to xmpp server with previous thread id

I am creating a chat application using xmpp over Ejabbered for server and smack for Android client

I established the connection, logging in, sending and receiving messages, and then I encountered the problem of disconnecting and reconnecting the user's network, which was solved using the Reconnecting Manger in smack and xmpp-0198, however there is a case when I need to create a new connection in smack, but use the previous session (stream) to get all the messages stored in this session (they are not stored in offline messages), and if I create a new connection with a new stream identifier, user messages will be lost.

So there is a connection designer for implementing this solution. or server configuration for storing thousands of messages in offline messages

+4
source share
2 answers

after many searches, finally I upgraded the Ejabberd server to the latest version 17.03

where they added a new mod_stream_mgmt module and changed the flow control behavior, so when I create a new connection, it overwrites the old one and receives unsent and not processed messages

To activate mod_stream_mgmt, I used the following configurations:

mod_stream_mgmt : 
  resume_timeout :60
  resend_on_timeout: true

: mod_ping , , , .

0

, -

  • : mod_offline .
  • mod_offline , - . 0.
  • PingManager . PingManager android -

XMPPTcpConnection -

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

XMPPTcpCOnnection -

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

private void configurePingManager() {
    pingManager.setPingInterval(ACCORDING_SERVER_PING_INTERVAL);
    pingManager.pingServerIfNecessary();
}
  • , stream_management , . , stream_management Android -

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

XMPPTcpCOnnection , , :

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

, .

+1

Source: https://habr.com/ru/post/1673873/


All Articles