Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
notizklotz #1
Member since Dec 2005 · 10 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
Subject: KeepAliveTimer generates Exception if connection not open
If XmppClientConnection.Open() is called, the KeepAliveTimer is started before the connection is actually open. This is a problem if there is currently no connection to the internet, or connecting to the Jabber server takes more longer than the keep alive intervall.

System.NullReferenceException was unhandled
  Message="NullReferenceException"
  StackTrace:
    bei agsXMPP.net.ClientSocket.Send()
    bei agsXMPP.net.ClientSocket.Send()
    bei agsXMPP.XmppConnection.Send()
    bei agsXMPP.XmppClientConnection.KeepAliveTick()
    bei System.Threading.Timer.ring()

I'm using the latest agsXMPP for .NET Compact 2.0 from SVN.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
i think we should start the KeepAlive timer after successfull login. We will fix this.
Can you set KeepAlive to false until this is fixed?

Alex
Avatar
Alex #3
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
should be fixed, i commited the code to SVN.

Alex
Avatar
notizklotz #4
Member since Dec 2005 · 10 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
Thanks for the quick response! It works now
Avatar
notizklotz #5
Member since Dec 2005 · 10 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
I discovered another problem: If there's an Exception while sending the keepalive ping, the Exception is not handled within the library. agsXMPP should handle those Exceptions by ignoring them to prevent the application from exiting due to an unhandled Exception.

Proposed patch:
Index: C:/Documents and Settings/gygax/My Documents/Visual Studio 2005/Projects/agsXMPP/XmppClientConnection.cs
===================================================================
--- C:/Documents and Settings/gygax/My Documents/Visual Studio 2005/Projects/agsXMPP/XmppClientConnection.cs    (revision 74)
+++ C:/Documents and Settings/gygax/My Documents/Visual Studio 2005/Projects/agsXMPP/XmppClientConnection.cs    (working copy)
@@ -996,7 +996,11 @@
         private void KeepAliveTick(Object state)
         {
             // Send a Space for Keep Alive
-            this.Send(" ");
+            try
+            {
+                this.Send(" ");
+            }
+            catch { }
         }
         #endregion
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

thank you for the patch. But the Keep Alive timer is only sending a SPACE over the socket to keep connections alive (NAT Timeouts).
So this will crash only if there is smth wrong with the Socket. I assume its trying to send on a closed socket. I have seen this once. Under some circumstances the connection gets closed without notifying the socket. I will take a look what i can do in ClientSocket.cs. I would be cool if you could try to put a try catch in the Send Method of the socket class and post the detailed exception here.

Alex
Avatar
notizklotz #7
Member since Dec 2005 · 10 posts · Location: Switzerland
Group memberships: Members
Show profile · Link to this post
The problem occurrs sometimes on the PDA if the WLAN connection is lost. I was able to reproduce this problem by just killing the WLAN connection while being connected to the Jabber server. But this behaviour showed up only once in about ten attempts.
The problem is not limited to the keepalive ping but does occurr on all methods which send something to the socket. I currently have all calls to XmppClientConnection.Send() and XmppClientConnection.Close() wrapped in a try/catch to handle those unreported disconnects. Because reusing a Socket object which had such an unreported disconnect seems to freeze my PDA I'm forceing agsXMPP to create a fresh Socket object before calls to XmppClientConnection.Open():

connection.SocketDisconnect();
connection.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
connection.Open();


Unfortunately, I didn't log the detailed exception of this problem. If I remember well it was a

System.IO.IOException: In die Übertragungsverbindung können keine Daten geschrieben werden.

I'll try to get you a detailed error log and a more info on when the problem arises.
Avatar
Alex #8
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Yes this is what happened to us once too.
On some pocket PC's we had another very weird behaviour. When we loose the wireless signal (to far away from the access point) then we get no socket exception and no socket close event. Just no data, and the socket is still alive. When we have Wireless signal again then we get the packets, messages etc... It behaves like we never lost the wireless signal. This is very odd too. No idea if this is a design problem with WLAN on PPC and Smartphone.

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