Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
jcmag #1
Member since Jan 2007 · 9 posts
Group memberships: Members
Show profile · Link to this post
Subject: Handling disconnections
I have developed a bot which has to be online 24/24. Sometimes disconnections happened, and I would like to know the best ways to handle that.

For example, I see in my logs:
2007-05-04 23:49:21,745 ERROR [Core] - onXmppConnectionStateChanged : Disconnected
2007-05-04 23:49:21,761 DEBUG [Core] - Closed!! Re-opening...
2007-05-04 23:49:21,761 ERROR [Core] - onXmppConnectionStateChanged : Connecting
2007-05-04 23:49:23,527 ERROR [Core] - onError : System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at agsXMPP.net.ClientSocket.EndConnect(IAsyncResult ar)
2007-05-04 23:49:23,527 ERROR [Core] - onSocketError : System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it
   at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   at agsXMPP.net.ClientSocket.EndConnect(IAsyncResult ar)
2007-05-04 23:49:23,542 ERROR [Core] - onXmppConnectionStateChanged : Disconnected
2007-05-04 23:49:23,542 DEBUG [Core] - Closed!! Re-opening...

etc.etc.

The first message is logged in the "onXmppConnectionStateChanged" event handler, you can see that my bot is disconnected.
The second message ("Closed!! Re-opening...") is logged in the "OnClose" event handler. Here I re-open the connection (by calling XmppClientConnection.Open) ; is it correct to do that?
Then you can see that the bot is trying to reconnect but there are socket exceptions, so it is disconnected again and a new connection attempt is made.

This loop is repeated until the connection succeeds (one hour later):
2007-05-05 00:47:29,610 ERROR [Core] - onXmppConnectionStateChanged : Disconnected
2007-05-05 00:47:29,610 DEBUG [Core] - Closed!! Re-opening...
2007-05-05 00:47:29,610 ERROR [Core] - onXmppConnectionStateChanged : Connecting
2007-05-05 00:47:30,485 ERROR [Core] - onXmppConnectionStateChanged : Connected

But in this case the bot doesn't appear online, because some events are missing, here is the correct sequence:
2007-05-08 17:46:17,953 ERROR [Core] - onXmppConnectionStateChanged : Connecting
2007-05-08 17:46:19,031 ERROR [Core] - onXmppConnectionStateChanged : Connected
2007-05-08 17:46:19,406 ERROR [Core] - onXmppConnectionStateChanged : Securing
2007-05-08 17:46:19,734 ERROR [Core] - onXmppConnectionStateChanged : Authenticating
2007-05-08 17:46:22,000 ERROR [Core] - onXmppConnectionStateChanged : Authenticated
2007-05-08 17:46:22,312 ERROR [Core] - onXmppConnectionStateChanged : Binding
2007-05-08 17:46:22,703 ERROR [Core] - onXmppConnectionStateChanged : Binded
2007-05-08 17:46:22,703 ERROR [Core] - onXmppConnectionStateChanged : StartSession
2007-05-08 17:46:23,015 ERROR [Core] - onXmppConnectionStateChanged : SessionStarted
2007-05-08 17:46:23,015 DEBUG [Core] - Logged in.

I hope my explanations are understandable ;)
So what is the best way to handle disconnections and provide automatic reconnections?
Thanks in advance
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Hi jcmag,

I think i understood you correct :).

Reopening the connection in the OnClose event is fine if you want your bot stay always online. But we normally use a timer there. Because i think if the internet connection is down or you got disconnected for some reason it's better to wait some seconds before reconnecting. Otherwise you could have 60 connection attempts per minute and more. In this case many xmpp servers or firewalls will block your IP then.

We normally try to reconnect immediately, if the reconnect fails then we set the timer with a interval of 10 seconds and increase it with every failed reconnect until its 120 seconds (10, 30, 60, 120). This logic works very well for us.

Did you send your Presence when the bot does not show online? Can you show us the debug XML? If you send your presence and it does not show online then i assume that there is a server probem.
Software Developer
AG-Software
Avatar
jcmag #3
Member since Jan 2007 · 9 posts
Group memberships: Members
Show profile · Link to this post
We normally try to reconnect immediately, if the reconnect fails then we set the timer with a interval of 10 seconds and increase it with every failed reconnect until its 120 seconds (10, 30, 60, 120). This logic works very well for us.
ok, I'll do that, thanks  :-)

Did you send your Presence when the bot does not show online? Can you show us the debug XML? If you send your presence and it does not show online then i assume that there is a server probem.
I don't understand. Do you mean "send your Presence" from the client or server? On the server-side I call SendMyPresence in the onLogin event handler but as you can see in my previous post sometimes when a reconnection occurs it stops at the "connected" event (there is no  "Securing", "Authenticating" etc. events and also no onLogin event)
Avatar
Alex #4
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by jcmag:
I don't understand. Do you mean "send your Presence" from the client or server? On the server-side I call SendMyPresence in the onLogin event handler but as you can see in my previous post sometimes when a reconnection occurs it stops at the "connected" event (there is no  "Securing", "Authenticating" etc. events and also no onLogin event)

Can you post your debug XML? Then we can see where it stops.

Alex
Alexander Gnauck
AG-Software
Avatar
ayyrk #5
Member since Jul 2007 · 92 posts
Group memberships: Members, Premium
Show profile · Link to this post
Subject: handling disconnections
Hi - my topic is still "handling disconnections". I am just getting started with agsxmpp sdk. My application handles invite, accept, roster management, and messaging. Basically I studied the miniclient ( excellent example ) and incorporated the SDK into my application.

OpenFire Server, Spark Desktop Clients, Windows Mobile 5 GPRS AT&T devices

I am still learning but I have this situation now:  The mobile device throws a timeout exception on a socket read. It happens after 5 minutes. The spark clients don't see this device as unavailable. Shouldn't the spark clients get a presence update that the mobile device is offline?

Also - if I just power off the device is there a way to signal the spark client that the device is unavailable? How long does the mobile client linger in the spark roster as available after it goes out of GPRS coverage?

And, what is the correct recovery when the socket timeout exception is thrown? Is it correct to reconnect from within the "xmpp close" call back?


Thanks!!!!  I appreciate the work you've done on this SDK.

-Ayyrk
Avatar
Alex #6
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by ayyrk:
I am still learning but I have this situation now:  The mobile device throws a timeout exception on a socket read. It happens after 5 minutes. The spark clients don't see this device as unavailable. Shouldn't the spark clients get a presence update that the mobile device is offline?

As long as the server did not notice that your connection is not alive anymore the other client (Spark) will not get the unavailable presence and still shows you online.

Quote by ayyrk:
Also - if I just power off the device is there a way to signal the spark client that the device is unavailable? How long does the mobile client linger in the spark roster as available after it goes out of GPRS coverage?

same here, If you don't log off properly and the server does not notice your broken connection the other client will not get the unavailable presence and show you as online.
Close your connection properly whenever possible. Not in all cases you get an exception when the tcp/ip connection breaks. This is the reason why the server sometimes assumes your connection still as alive while its broken. But the most servers and clients send keep alive packets to detect broken connection. With the next keep alive packet the server should get a socket exception then and close your session. We send this keep alive in agsXMPP by default every 120 seconds. We don't know what Jive does in Openfire.

Quote by ayyrk:
And, what is the correct recovery when the socket timeout exception is thrown? Is it correct to reconnect from within the "xmpp close" call back?

yes this is correct

Alex
Alexander Gnauck
AG-Software
Avatar
[gja] #7
Member since Jul 2009 · 19 posts
Group memberships: Members
Show profile · Link to this post
Subject: same problem
having trouble with disconnections.

i had a problem in broken connections..i've done simulation,i pull out the LAN to get broken connection..then i try to reconnect in OnClose event..unfortunately,The OnLogin event did not trigger anymore..why?..

thanks for all the reply..
Avatar
Alex #8
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
please look in the other threads where I have suggested the best logic for reconnects.
And check the error events, if it doesn't login again there is a reason this behaviour.

Alex
Alexander Gnauck
AG-Software
This post was edited on 2009-08-29, 12:35 by Alex.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: agsXMPP SDK Support RSS