Smack doesn't detect broken connection

Hello

I am using Smack for android to connect to openfire server.

I am using XMPPConnection.isConnected() to detect if the user is connected to the server or not

My issue is that isConnected() return true, although internet connection is broken. This behavior can be reproduced following these steps:

  1. Turn on WiFi hotspot on a mobile device X.

  2. Connect from mobile device Y to the hotspot.

  3. Connect to openfire from Y: XMPPConnection.isConnected() return true

  4. Disable mobile data from device X, without turning off the WiFi hotspot.

  5. XMPPConnection.isConnected() still returns true, although there is no internet connection.

  6. If you tried to send a message using XMPPConnection.sendPacket(), it will be lost and there is no error or exception given.

So Is there any alternative way to detect broken connection with openfire?

isConnected() merely returns the internal state of Smack. There is no way Smack could reliable detect a broken connection in your scenario (if the OS doesn’t propagate the broken TCP pipe up to the socket used by Smack, which is not always the case).

If you want to know if you are still connected to the server, use PingManager.pingMyServer(). If it returns ‘true’ you are still connected, if it returns ‘false’ you are either disconnected, or the server’s pong didn’t arrive within the default reply timeout.

2 Likes

This topic was automatically closed 62 days after the last reply. New replies are no longer allowed.