So in order to know if there’s still an active data connection, I’m sending a ping every like 5 minute interval, and waiting for the server to respond. So basically, I’m using the iq id as a key on this pinging method. I’ll send a ping, and store the iq id, and i’ll say assume that noDataConnection = true. Now, if I receive a pong with the same iq id, I assume that the connection is alive, so I’ll set noDataConnection = false. However, if there’s no data connection, i’ll continue to send pings setting noDataConnection = true, and never receiving any so it will remain true unless it recovers and obtained a data connection.
Excerpt from http://xmpp.org/extensions/xep-0199.html#s2c:
PING:
<iq from='juliet@capulet.lit/balcony' to='capulet.lit' id='c2s1' type='get'>
<ping xmlns='urn:xmpp:ping'/>
</iq>
PONG:
<iq from='capulet.lit' to='juliet@capulet.lit/balcony' id='c2s1' type='result'/>
My only concern about this, is what if I received an iq that isn’t a result of my ping and my application will assume that noDataConnection = true, since the iq id that it receives doesn’t match up to my ping iq id that is sent. Is there a way to know if the iq that I received is a result of my ping?
Thanks.
My solution is to prefix the iq id that i’ve sent with a text “ping”, so basically if i received an iq prefix with “ping”, then it is the pong of my ping.