5

I'm building a chat application using xmpp over Ejabbered for server and smack for android client

I've established connecting , login , send and receiving messages ,then I've faced a problem with user network disconnecting and reconnecting , which has been solved by Reconnecting Manger in smack and xmpp-0198, however there is a case where i need to create a new connection in smack but use the previous session (stream) to get all the messages stored in that session (they don't get stored to offline messages) ,and if i create a new connection with new stream id , user messages get lost .

so is there a connection constructor to implement this solution . or server side configuration to store thous messages to offline messages

Ahmed na
  • 1,084
  • 2
  • 13
  • 34
  • You can use mod_offline module at server side. – Hare Kumar Apr 05 '17 at 18:29
  • mod_offline is added and working at the case of user is not Online with any clients , however if there is a resource (client connected with an open session ) then messages get stored in queue inside that session , in case of same client creating a new session messages get lost @HareKumar – Ahmed na Apr 07 '17 at 01:32

2 Answers2

1

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.

Barno
  • 766
  • 7
  • 15
  • what code added in sendSmAcknowledgement() and requestSmAcknowledgement() – Sathish Gadde Apr 10 '19 at 08:58
  • Am just started working with smack, please advise what is best interval time(ACCORDING_SERVER_PING_INTERVAL) for maintain stable session – Sathish Gadde Apr 10 '19 at 09:00
  • @SathishGadde Its generally 1 minute by default. But your server configuration can be different. Check the ping interval in server side and set it to client side Smack. – Barno May 14 '19 at 09:56
  • xmpp.client.idle.ping : true , in my server side. Not added any server_ping_interval. If possible please share propertyname with example – Sathish Gadde May 15 '19 at 07:32
  • @SathishGadde Look into this XEP https://xmpp.org/extensions/xep-0199.html – Barno May 22 '19 at 06:38
0

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 .

Ahmed na
  • 1,084
  • 2
  • 13
  • 34