Iām working on a mobile chat application, for the last few days I began to encounter problems with connection (my case works fine for the first time, but when my application disconnected (having lost a network connection or disconnected Wi-Fi or a bad network), then my application is reconnected but cannot send messages, but at the same time, the application can receive a message): To reconnect, I use reconnectionmanager
I am using smack4.1 library.
Error Details: The client is not connected or not connected
Thank you my connection and reconnection code -
XMPPTCPConnectionConfiguration.Builder connConfig = XMPPTCPConnectionConfiguration
.builder();
connConfig
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connConfig.setUsernameAndPassword(user, pass);
connConfig.setServiceName(SERVICE_NAME);
connConfig.setHost(SERVER_HOST);
connConfig.setPort(SERVER_PORT);
connConfig.setDebuggerEnabled(true);
connConfig.setConnectTimeout(25000);
XMPPTCPConnectionConfiguration configuration = connConfig.build();
connection = new XMPPTCPConnection(configuration);
connection.setUseStreamManagement(true);
connection.setUseStreamManagementResumption(true);
connection.setReplyToUnknownIq(true);
connection.setPacketReplyTimeout(25000);
ReconnectionManager manager = ReconnectionManager.getInstanceFor(connection);
manager.setFixedDelay(10);
ReconnectionManager.setDefaultReconnectionPolicy (ReconnectionManager.ReconnectionPolicy.FIXED_DELAY);
manager.enableAutomaticReconnection();
ReconnectionManager.setEnabledPerDefault(true);
connection.addConnectionListener(new ConnectionListener() {
@Override
public void connected(XMPPConnection xmppConnection) {
IsConnected = true;
}
@Override
public void authenticated(XMPPConnection xmppConnection, boolean bt) {}
@Override
public void connectionClosed() {
IsConnected = false;
}
@Override
public void connectionClosedOnError(Exception e) {
IsConnected = false;
}
@Override
public void reconnectionSuccessful() {
IsConnected = true;
}
@Override
public void reconnectingIn(int i) {
}
@Override
public void reconnectionFailed(Exception e) {
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
To send a message to user connection.sendStanza (messsageObj);