Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
maincoon #1
Member since May 2011 · 13 posts
Group memberships: Members
Show profile · Link to this post
Subject: XmppConnectionState stays in Connecting state after Disconnect
I found bugreport here http://forum.ag-software.de/thread/679-ClientSocket-does-n…, but not sure this is the same issue.

To simulate this run following steps:

1. connect to server
My client uses "OnClose" handler to handle server disconnects. Just as suggestion here - I'd like agsXMPP has "OnDisconnect" or "OnPeerDisconnect" event handler for this purpose because "OnClose" event launches also when I'm closing connection manually.

2. disable network connection in your system (or just plug network cabel offl)
Debugging "OnClose" event here shows that XMPP connection state is "Disconnected" so I'm trying to reconnect here just calling "Open". Note that for now we still have no internet connection. Also "Open" call not so async as it ought to be, i believe name resolving is still syncronous operation. So here after call we have state "Connecting"

3. wait for a second and we'll got launched "OnError" handler
Connection here still in "Connecting" state so I've decided to close connection and call "Close" and even "SocketDisconnect" (it's just in case something goes wrong). So here is the most interesting part of my story - sometimes (I'd said almost always) connection remains and just hangs in "Connecting" state no matter hos much time I'll call "Close" again.

What am I doing wrong?
Avatar
maincoon #2
Member since May 2011 · 13 posts
Group memberships: Members
Show profile · Link to this post
Well. A bit more stuff about this. It looks like problem dedicated to resolver errors.
Anyone?
Avatar
Alex #3
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
are you running the latest SVN code?

Is it only the connection state which is wrong for you, or is the also a race conditions which prevents the library from the reconnect once your Internet is back?
Avatar
zackrspv #4
Member since Sep 2010 · 29 posts
Group memberships: Members
Show profile · Link to this post
When i first started coding a technical support chat and open chat system for my team, I ran into many issues (Alex can attest to that lol).  One of the main issues was the disconnect handling; as you stated there is no 'OnDisconnect' feature.

After reading up on the XEP's, and RFC's, I was able to adjust my logic to understanding that, as i needed a persistent connection for each of the users who log into the system (something that means they are not logging into the server themsevles, joining the rooms themselves, etc, I needed a proper method to handle disconnects, reconnects, errors, and then finally the rejoin commands.

Like you, I ran into an issue where the OnClose would always show the improper state of XMPP, but after doing a bit more research with the example project that Alex provides with the AGSXMPP download, I figured out that I wasn't declaring my server settings and variables right within the script.

How are you declaring your settings?  How are you connecting?  And where are you declaring your event handlers?  Are you disposing of the XMPP object?  Are you closing and killing the socket (both?).

If you have a code example, i'd love to look at it.

Alex is a busy guy and i'm having a blast, so helping and learning more is fine by me.

The biggest thing I had to learn here is that, when a user has no connection, the Winsock, and system settings will vary about how long they will allow the timeout to take place.  Some systems will return almost immedaitely, some up to 300 seconds or more, so it's best to remove the OS and network from the factor, and handle the reconnect yourself.

So, in my case:  I check it every 5 seconds for 4 minutes, and after 4 minutes, i close the application.  NO need to wait longer, imho. 

My timer is situated to know what the states are.  If it's reconnected, it disables the timer and returns; if it's still disconnected, then it just continues on.  It also checks retry count to quite after 4 minutes.

I then close the XMPP object connection with XMPP.Close(), then re-declare my system settings (this is not necessary if you declare your XMPP object as an application (class in my case) wide object, but always better to be safe than sorry).  I then call the XMPP.Open() and the timer returns.  From there, the xmpp handlers already registered in the from constructor take over, and if the connection doesn't connect, the OnClose fires, and the checks happen all over again.

By taking the OS out, even the most flaky of user connections is handled by my application (even those on verizon and sprint air cards that always disconnect), and then they reconnect w/o any loss of data or system error that's not handled. 

I hope that long ramble made sense lol it's about 11pm where i am at the moment lol.

Alex (P.S.) thanks for the IBB examples, I have converted them to C#, and am putting them into my application.  Once I do, i'll go ahead and shot some examples back over so that people can see how to do that with AGS.
This post was edited on 2011-06-09, 09:03 by zackrspv.
Avatar
Alex #5
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
zackrspv, thanks for your detailed posts.

And I agree, we have seen very strange stuff happening in the last years with the networks. Most programmers unplug their network cable for their disconnect tests only. Such tests are not very significant IMHO, because such a disconnect is detected immediately by most network drivers. In production and real live you have to handle much more, and as zackrspv said it can take sometimes a long time until we get the error or disconnect on the socket classes. The socket class is all we can rely on.

In addition you can hook up network events of the OS or check the InternetConnectState with APIs. When they tell you a network loss faster than the socket in MatriX you can manual Close the connection and then reconnect later.

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 RSS