powered by Jive Software

SM: close connection if a request is not acknowledged


Sometimes, the connection with the server is lost without Smack being able to detect it.

Logs: The client no longer receive <a xmlns='urn:xmpp:sm:3' h='x'/>

2019-10-15 09:54:38.038 21034-21331/integration D/SMACK: SENT (0): <message to=‘******’ id='hVOwP-22' type='chat'><body>Salut</body></message><r xmlns='urn:xmpp:sm:3'/>
2019-10-15 09:56:12.129 21034-21331/integration D/SMACK: SENT (0): <message to=‘******’ id='hVOwP-23’ type='chat'><body>Bonjour</body></message><r xmlns='urn:xmpp:sm:3'/>

The only way I see to detect broken connection (besides using PingManager, which is not available on the server) is to check that the stanza has been acknowledged (with SM) in time. Unfortunately, I have no listener to detect sending requests <r xmlns = 'urn: xmpp: sm: 3' />, which are automatically sent by the lib ? How could I detect a request that was not acknowledged?

Thanks in advance for your help

Smack: 4.3.4

Every XMPP compliant server responds to XMPP pings.

You should never find yourself in a situation where you need to detect that a SM request was not acknowledged. If you want to check if your connection is alive, use PingManager.pingMyServer().

Thank you for your answers.

Unless I’m mistaken, it’s not write in the RFC that ping support is required.

Besides in the rfc, it’s indicated that it’s possible to check that the connection is still alive with SM.

In our app, we need to quickly detect that the connection has been broken. Usign SM rather than Ping would allow us to detect faster than a message wasn’t sent because we can’t send a ping after each message to avoid overloading the server

That is right. But it is written in the RFC that every IQ request must be answered.

Actually the RFC says quite the opposite

If the underlying TCP connection is dead, stream-level checks (e.g., [XEP-0199] and [XEP-0198]) are ineffective.

(emphasis mine)

You can not detect it faster with SM. And, if anything, SM requests are more expensive, in terms of computational power, to handle by the server than pings.

tl;dr: Use XEP-0198 Pings to detect if the connection is still alive.

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