Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
what is the best way to find out whether we are connected to server?
Avatar
mwaqas #1
Member since Mar 2012 · 10 posts · Location: Finland
Group memberships: Members
Show profile · Link to this post
Subject: Best way to find out whether we are connected to server
Hello,
In mobile world connection to the server can be tricky sometimes, what is the best method to find out whether we are connected to server or not? currently i use XmppClient.StreamActive method when app starts or activated and also just before sending any message, is that the correct way?

Thanks in advance for your reply,
-Waqas
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
When you get disconnected you should always get the OnClose event as soon as MatriX detects the connection loss. So you should watch the OnClose event.

StreamActive gets set to true as soon as MatriX was able to establish an XMPP stream. But this does not mean that you session is authenticated and ready at this time. So you should rely on OnRosterEnd, OnAuthenticate, OnPresense or some other event. Take the one which works best for you.

Also Windows Phone stops any code and closes the connection when your app gets deactivated. When the app gets deactivated you should try to Close the connection when possible and wait for the OnClose event. This is sometimes not possible because the OS freezes any code. For this reason many of our users throw away the complete XmppClient and create a new one when the app is reactivated. Or handle all this crazy situations which can occur, eg. the OnClose can raise on reactivation.

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: