Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
lead2demo2 #1
Member since Dec 2010 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Cannot connect to messaging application using Matrix .NET
I had a working version of a messaging application using agsXMPP. We decide to update our app. using Matrix.
After changing my code to be compatible to matrix, now i keepp getting an "ArgumentException was unhandled: {"Delegate to an instance method cannot have null 'this'."}
The error is OnStreamError. If anyone can help me, I will appreciate it a lot!!!!

Thanks in advance!!!

Here is my code:


using System;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matrix.Xmpp.XData;
using Matrix.Xmpp.Client;
using Matrix;
using Matrix.Xml;
using Message = Matrix.Xmpp.Client.Message;


namespace app.Logic.OpenFire
{
    public class ConnectionDirector
    {
        public event EventHandler<PresenceEventArgs> OnPresence;
        public event EventHandler<MessageEventArgs> OnMessage;
        public event EventHandler<Matrix.EventArgs> OnLogin;
        public event EventHandler<Matrix.EventArgs> OnClose;
        public event EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs> OnAuthError;
        public event EventHandler<ExceptionEventArgs> OnError;
        public event EventHandler<StreamErrorEventArgs> OnStreamError;
        public event NotificationHandler OnNotification;
                
        public Matrix.Jid GetUser()
        {
            return _user;
        }
        #region Private Variables
        private  Matrix.Jid _user;
        private string _password;

        private XmppClient _xmppCon;
      
        private Exception _loginException;
        private bool _connected = false;
        #endregion

        public ConnectionDirector(string username, string server, string password)
            : this(username + "@" + server, password)
        {
        }

        public ConnectionDirector(string username, string password)
        {

            _xmppCon = new XmppClient();
            _user = new Matrix.Jid(username);
            _password = password;
           
        }

        #region Login/Logout methods
        public void LogOut()
        {
            if (_connected)
            {
                _xmppCon.Close();
                _connected = false;
            }
        }
        public bool Login()
        {
            bool loginSuccessfull = true;

            if (!_connected)
            {
_xmppCon.Password = _password;
                _xmppCon.Username = _user.User;// +"@" + _user.Server;
                _xmppCon.XmppDomain = _user.Server;
                _xmppCon.StartTls = false;
               _xmppCon.UseSso = false;
                _xmppCon.KeepAliveInterval = 60;
                _xmppCon.AutoPresence = true;
                _xmppCon.AutoRoster = true;
                _xmppCon.XmppDomain = "openfire." + _user.Server;
                _xmppCon.Hostname = "openfire.erei.com";
                _xmppCon.AutoPresence = true;

            
                // Connect to the server now
                // !!! this is asynchronous !!!

                 _xmppCon.OnMessage += new EventHandler<MessageEventArgs>(OnMessage);
                _xmppCon.OnLogin += new EventHandler<Matrix.EventArgs>(OnLogin);
                _xmppCon.OnClose += new EventHandler<Matrix.EventArgs>(OnClose);
                _xmppCon.OnAuthError += new EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs>(OnAuthError);
                _xmppCon.OnSendXml += new EventHandler<TextEventArgs>(OnSendXml);
                _xmppCon.OnError += new EventHandler< Matrix.ExceptionEventArgs>(OnError);

                //_xmppCon.OnXmppConnectionStateChanged += new XmppConnectionStateHandler(xmppCon_OnXmppConnectionStateChanged);*************************FALTA POR AGREGAR

                //_xmppCon_OnSocketError += new EventHandler<Matrix.ExceptionEventArgs>(OnSocketError);
                //_xmppCon.OnSocketError += new ErrorHandler(_xmppCon_OnSocketError);***************************FALTA POR AGREGAR
                _xmppCon.OnStreamError += new EventHandler<StreamErrorEventArgs>(OnStreamError);
                _xmppCon.Open();//_user.Bare, _password);

               
                   
               

            }

            return loginSuccessfull;

        }
        #endregion

        #region System Messaging Methods
        public bool SendNotification(string userToDeliverTo, Notifier.Objects.RemoteCommunication.RemoteCommunication message)
        {
          //sendnotification method        
 }

        #endregion

        #region User Messaging Methods
        public bool SendMessage(string userToDeliverTo, string message)
        {
//sendmessage method
}

        public bool ChangeStatus( Matrix.Xmpp.Show st)
        {
           //changestatus method
        }
        #endregion

        #region events with local scope application
        void xmppCon_OnLogin(object sender, Matrix.EventArgs e)
        {
            _connected = true;
            if (OnLogin != null)
                xmppCon_OnLogin(sender,e);
        }

        void xmppCon_OnAuthError(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e)
        {
            //onautherror method
        }

        void xmppCon_OnClose(object sender, Matrix.EventArgs e)
        {
           //onclose method
        }
       
        void xmppCon_OnMessage(object sender, MessageEventArgs msg)
        {
//onmessage method

                  }

        #region Detect connection with server for Errors
        void xmppCon_OnError(object sender, Exception ex)
        {
            if (OnError != null)
              }
void xmppCon_OnPresence(object sender, Presence pres)
        {
            if (OnPresence != null)
                xmppCon_OnPresence(sender, pres);
        }
void _xmppCon_OnStreamError(object sender, StreamErrorEventArgs e)
        {
            if (OnError != null)
            {
                Exception ex = new Exception(e.State.ToString());
                xmppCon_OnError(sender, ex);
            }
        }

       
        void OnSendXml(object sender, Matrix.TextEventArgs e)
        {
            OnSendXml(sender, e);
            System.Threading.Thread.Sleep(165);
        }
}
}
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Can you please post the full stacktrace of your exception?

I see 2 errors in your code.

here you have an infinite loop
  1. void xmppCon_OnLogin(object sender, Matrix.EventArgs e)
  2. {
  3.     _connected = true;
  4.     if (OnLogin != null)
  5.         xmppCon_OnLogin(sender, e);
  6. }

it looks weird to me that you build the jid and then still add a subdomain to the user part.

  1. _xmppCon.XmppDomain = "openfire." + _user.Server;

Alex
Avatar
lead2demo2 #3
Member since Dec 2010 · 3 posts
Group memberships: Members
Show profile · Link to this post
Do you know if the evaluation copy of Matrix it can limit the connectivity for my application? Is there are x days of full usage?

After I change my LogIn method my application runs but when finish running through each method it never connects.

 void xmppCon_OnLogin(object sender, Matrix.EventArgs e)
        {
            _connected = true;
          
                xmppCon_OnLogin(sender,e);
        }
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The evaluation version is not limited in time. It only shows a nagscreen which is a problem when your app has no UI. In this case we can provide you a time limited trial key.

Does the sample MiniClient app work for you?
Make sure that .NET 3.5 SP1 is installed.

Alex
Avatar
lead2demo2 #5
Member since Dec 2010 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hello Alex.

Yes, MiniClient works for me.

I'm using a different application based on windows forms connecting it to Openfire. Could you provide me with a trial key? That would be awesome. Here is my email alantero@erei.com

I want to test my application without the snagscreen and find out if that could be my propblem and if it isn't dig more. Eventually, we will be buying the license for matrix but first we want to see our application up and running.

Thank you.
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you have email.

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: