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
I think one of the following will solve your issue-
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();
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With