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);
}
}
}
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);
}
}
}