Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
dandorey #1
Member since Aug 2009 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Exception on loss of network connection
In a scenario where a user looses connection to the chat server we are seeing the following exception being thrown. Once started this exception will continue to be thrown every 10 seconds or so. Even reestablishing the connection does not correct it.

Can anyone tell me what might be going on here or how I can handle this error gracefully?

Also is there any reconnection built in to automatically reconnect to the server when a network connection is reestablished?


Exception Message="Object reference not set to an instance of an object." StackTrace="  
at Matrix.Net.ClientSocket.get_Connected()
  
at Matrix.Net.ClientSocket.Send(Byte[] data)
  
at Matrix.XmppStream.SendData(String xml)
  
at Matrix.XmppStream.Send(String xml)
  
at Matrix.XmppStream.KeepAliveTick(Object sender, EventArgs e)
  
at System.Windows.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
  
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)"
DateTime="2009-11-13T18:49:58.3491995Z"

ADDITION:

I've tried identifying your unhandled exception in the main Application UnhandledException and then tried calling the XmppClient.Close() method. However that itself causes the same exception:

Object reference not set to an instance of an object.: e.Message='Object reference not set to an instance of an object.' e.StackTrace='   at Matrix.Net.ClientSocket.get_Connected()
   at Matrix.Net.ClientSocket.Send(Byte[] data)
   at Matrix.XmppStream.SendData(String xml)
   at Matrix.XmppStream.Send(String xml)
   at Matrix.XmppStream.SendStreamFooter()
   at Matrix.XmppStream.Close()
   at Matrix.Xmpp.Client.XmppClient.Close()
   at LookNow.Pages.ChatManager.Disconnect()
This post was edited on 2009-11-13, 22:13 by dandorey.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by dandorey:
Also is there any reconnection built in to automatically reconnect to the server when a network connection is reestablished?

currently there is not, because different applications need different reconnect logic. But we consider adding automatic reconnect with a release i nthe future.

To me it looks like there is a problem with the keepalive timer. Can you try to disable keepalives to see if this causes the problem (KeepAliveInterval = 0)?
Do you have a small sample test case which would help us to fix the problem? In the code the keep alive timer should get destroyed when the socket gets disconnected.

Regards,
Alex
Avatar
dandorey #3
Member since Aug 2009 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

If I disable the keepalive timer (docs said set it to -1) then I do not get this issue. However without the keepalive timer, my connection closes after about 5 minutes of inactivity so this does not seem like a viable options. Is there anything I can do in the mean time? I could create my own timer in my wrapping class if there is anything I can call to make it not timeout...?

I'll post some of my code here, but I'm not doing anything complicated. I'm just creating a client, sending a message to a user, disabling my network connection and then waiting a few minutes before the exception is thrown.

I don't know if it would matter (probably not), but I'm not using anything to do with the PresenceManager. Just using the client directly.

            _xmppClient = new XmppClient();

            _xmppClient.OnLogin += new EventHandler<Matrix.EventArgs>(xmppClient_OnLogin);
            _xmppClient.OnAuthError += new EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs>(xmppClient_OnAuthError);
            _xmppClient.OnError += new EventHandler<ExceptionEventArgs>(xmppClient_OnError);
            _xmppClient.OnMessage += new EventHandler<MessageEventArgs>(xmppClient_OnMessage);
            _xmppClient.OnClose += new EventHandler<Matrix.EventArgs>(xmppClient_OnClose);

             Matrix.License.LicenseManager.SetLicense(lic);

                _xmppClient.Username = _user.ID.ToString();
                _xmppClient.Password = _user.Password;
                _xmppClient.Hostname = App.CurrentApp.JabberHostname;
                _xmppClient.XmppDomain = App.CurrentApp.JabberDomain;
                _xmppClient.Port = App.CurrentApp.JabberPort;
                _xmppClient.Priority = App.CurrentApp.JabberPriority;
                _xmppClient.Open();

                 //sending a message
                 Message xmppMessage = new Message();
                Jid jid = new Jid(message.Recipients[0].ID.ToString(), message.Recipients[0].JabberServer, String.Empty);
                xmppMessage.To = jid;
                xmppMessage.Type = MessageType.chat;
                xmppMessage.Body = message.Message;
                xmppMessage.Add(new XElement(FIRSTNANME_TAG, _user.firstName));
                xmppMessage.Add(new XElement(LASTNAME_TAG, _user.lastName));

                _xmppClient.Send(xmppMessage);
This post was edited on 2009-11-16, 19:55 by dandorey.
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the keep alive timer sends a space char every x minutes to keep the connection alive.
It looks like there is problem with destroying the timer on Disconnect or connection loss.

In the meantime you can use an own timer e.g. every 120 seconds and to a XmppClient.Send(" ") each timer interval.

Can you give me more info about your connection loss? Can you cause the problem when you unplug the network cable? I need this info to debug this problem.

Alex
Avatar
dandorey #5
Member since Aug 2009 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hey Alex,

Yes, I can reproduce by unplugging the network connection. This is not working for you?

Dan
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by dandorey on 2009-11-20, 19:48:
1258742920

I made several tests, but I can't. The keep alive timer gets always destroyed properly here.
maybe you can give me more information or write a small test case.

Alex
Avatar
Alex #7
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hi Dan,

can you check if you get a connection close before this error occurs?
Do you get the exceptions before you try to reconnect manual, or after you try to reconnect?
can you post also your reconnect code, or explain the logic of your reconnect code and from which events it gets executed?

I made some changes which should prevent this error, but because I can't cause this error I still don't know why the timer gets not disposed.
Can you contact me by email? Then I can send you a new MatriX version.

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: