Smack Keep Alive Packet Delay after login in

I am developing a instant chat app on Android using smack API. I set the KeepAliveInterval to 2 seconds using the following code:

SmackConfiguration.setKeepAliveInterval(2000);

However, I checked the log and found that KeepAliveInterval was not sent out until nearly 20 seconds after I logged in. I used Openfire as server and set the idle disconnection threshold to 15 seconds. So my client was disconnected before the first keep alive packet was sent out.

The app I am developing requires real-time monitoring of user presence, so I cannot reduce the idle disconnection threshold, the only option for me is to set the KeepAliveInterval to a small value.

Can anyone help me with this? Thanks.

I don’t think you really want to ping the server every 2 seconds, seems like extreme overkill.

There is a hard coded 15s + the keepAliveInterval delay before the first heartbeat. This is to allow time to finish connection negotiation. You will have to set your threshold higher.

Thanks for your reply. If what you said is true, then there has to be a 15-second delay before the server recognizes a disconnected client. During that delay, the server will errorneously assume the client is still online, so any message send to the client will be sent as online messages and hence get lost. How to resolve this problem of message lost?

Well, when clients disconnect, they send a disconnect message, they don’t leave the server waiting for idle expiration.