powered by Jive Software

Best way to KeepAlive connection with xmpp server in android

android

#1

I am working on chat application and using ejabberd saas edition as xmpp server for it.I am using smack library ver-4.2.3,To keep connection alive i am using ping manager.Here is the code i am using.

ReconnectionManager.getInstanceFor(AppController.mXmpptcpConnection).enableAutomaticReconnection();
ServerPingWithAlarmManager.onCreate(context);
ServerPingWithAlarmManager.getInstanceFor(AppController.mXmpptcpConnection).setEnabled(true);
ReconnectionManager.setEnabledPerDefault(true);

    //int i = 1;
   // PingManager.setDefaultPingInterval(i);
    PingManager.getInstanceFor(AppController.mXmpptcpConnection).setPingInterval(300);

I am using sticky-service also for connection, but when i keep my application open (ideal-state) for 15-20 mins then the connection is lost, so i am using ping manger to resolve this issue. Is there any other better way of doing it or ping manager is the only option?


#2

did you get any specific error or stack trace in your log while connection closing?

Have you checked the ping manager working properly and IQ for ping is exchanging from server to client and does server responding for the ping intreval?

you might need to set debugger on to catch all type of the error occuring at smack.

If you server closing server forcefully then you must need to change the configuration.

Please post you log while connection is closing it will help us to understand better


#3

Thanks for your response!
Yes, I have checked the IQ for ping. Following are the stanzas sent and received:

//sent ping stanza:

<iq to='kisan-test.m.in-app.io' id='Ra6qt-577' type='get'><ping xmlns='urn:xmpp:ping'/></iq>

//received stanza:

<iq from='XmmpDomain' to='2e8b7cee-c279-4958-acff-b0937418e164@XmppDomain/android_app1525673154502' type='error' xml:lang='en' id='MSTtl-338'><ping xmlns='urn:xmpp:ping'/><error code='501' type='cancel'><feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/><text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'>No module is handling this query</text></error></iq><r xmlns='urn:xmpp:sm:3'/>

Please let me know what am I doing wrong.


#4

How frequently it is called?

Both the stanza id should be same why it is diffrent?

It also seems your server doesn’t support ping as it shows

No module is handling this query.

You might need to install ping module if you are using ejabbered.


#5

Thanks for quick reply
I am sending a ping to the server after every 5 min, and we are using ejabberd saas edition as our server, I didn’t know it supports or not, if ping module is not support by our server, Is their is any other possible way to stay connected(keep connection alive)?

Is This is only possible way to stay connected means by pinging to the server

Thanks in advance


#6

without ping-pong it is difficult for any server to detect wheather it is connected with client is connected with the server or not.

you can add ping module and if you are using openfire you can set some property with client configuration how to process with client.


#7

Hello,
Thanks for the Response
Our server is not supports ping module, so I want to send whitespace stanza to ejabberd server, how can I send whitespace keepAlive stanza to ejabberd server using smack

Thanks in advance


#8

1 ) which server are you using which is not supporting ping module.

2 ) If ping is not supported then you need a re-connection manager to manage connection to auto connect on incremental time out period.


#9

As I wrote in How do I send regular heartbeat packets to the server so it won’t disconnect the client?, most servers will correct answer to client pings. It is unlikely that you have a server which doesn’t.