Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
martinbach #1
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Subject: Matrix for .net - minimal required code for connecting to e.g. Openfire
Hi Alex,

I tried to connect to my local Openfire server (standard config. and one additional user "maltin").
It seems that I can't connect (Openfire shows no active user in the admin console).

I used the example from Silvelight with minimal changes.

Here is the used code snippet:

XmppClient xmppClient = new XmppClient();

xmppClient.Username = textBoxUsername.Text;  //e.g. maltin
xmppClient.Password = textBoxPassword.Text;  //e.g. secret
xmppClient.XmppDomain = textBoxDomain.Text;  //e.g. maltin@jabber.server.de
if (!String.IsNullOrEmpty(textBoxHostname.Text))   //e.g. jabber.server.de
    xmppClient.Hostname = textBoxHostname.Text;
xmppClient.Port = 5222;
xmppClient.Priority = 100;

// mppClient.ProxyHostname = "localhost";
// xmppClient.ProxyPort = 4503;


xmppClient.AutoPresence = false;
xmppClient.Priority = 1;
xmppClient.Status = "online";
xmppClient.Show = Matrix.Xmpp.Show.NONE;
xmppClient.ProxyType = Matrix.Net.Proxy.ProxyType.None;

// xmppClient.OnError += new EventHandler<Matrix.ExceptionEventArgs>(xmppClient_OnError);
// xmppClient.OnLogin += new EventHandler<Matrix.EventArgs>(xmppClient_OnLogin);
// xmppClient.OnAuthError += new EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs>(xmppClient_OnAuthError);

xmppClient.Open(); 

After open I would assume to see the active user in openfire.

1. What's wrong with my code (I used your lib MatriX .net not Silverlight)?
2. How can I check if I'm connected to the server ?

Thank you for giving me a hint.

Martin
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by martinbach:
xmppClient.XmppDomain = textBoxDomain.Text;  //e.g. maltin@jabber.server.de

This the node part only, in your case jabber.server.de.

Alex
Avatar
martinbach #3
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

thank you for the hint for MatriX for .net. Now the error message itself is gone but raises another two questions:

Two question:
1. What I have to code additionally, to get my user listed as "online" in the admin console of the jabber server Openfire
 (to be sure to be connected to the server) ?

2. Is the handler "OnLogin" always fired after a successfull xmppClient.Open() or are there differences between "Open" and "Login"?

Thank you for the help.

Martin
Avatar
Alex #4
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by martinbach:
Two question:
1. What I have to code additionally, to get my user listed as "online" in the admin console of the jabber server Openfire
 (to be sure to be connected to the server) ?

nothing, when tehre are no errors you should show as online.

Quote by martinbach:
2. Is the handler "OnLogin" always fired after a successfull xmppClient.Open() or are there differences between "Open" and "Login"?

yes, or one of the error handlers on failure.

Alex
Avatar
martinbach #5
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

after a longer period of trial and error and a workaround I'm now successful in connecting to openfire
(I'm not a professional  ;-)  ).

My workaround:
void xmppClient_OnSendXml(object sender, Matrix.TextEventArgs e)
        {
            WriteToLog("OnSendXml: " + e.ToString());
            Thread.Sleep(200);
         }

A question to my workaround:
Without "Thread.Sleep(200);" or a value smaller than 200 the connection process stops after the IQ and the connection fails. With "Thread.Sleep(200)" it connects succefully.
Is this an issue for an overrun of a too fast process or what is the problem (my problem) ?


A second - probably silly - question:
It seems that I have to code/use the handler "OnXmlSend" otherwise nothing happens.
Why do I have to code the handler (to use it as a hook to react on this event makes sense)?   

Thank you for your help.

Martin
Avatar
Alex #6
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
no, you don't have to subscribe to the Xml handlers.
I have attached a basic example client which works fine for me.

Alex
The author has attached one file to this post:
MiniClient.zip 203.4 kBytes
You have no permission to open this file.
Avatar
martinbach #7
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

great ! Using your lib it will help me a lot .

Thank you.

Martin
Avatar
martinbach #8
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

it's me again. Your miniClient helped me a lot.

But a question concerning XmppClient.Open() still exist.

I tried to isolate my miracle ;-)
and it seems that I have to use Thread.Sleep(200) in the xmppClient_OnSendXml(...) handler to get connected to my local openfire server. (with slowing down while connecting everything works great inkl. sending messages, ...)

I'm not a professional developer, but  ...
is it possible that the calls inside the XmppCient.Open() method are to fast in communication to my local openfire server that the connection can't be established (just in case)?

What let me feel this is that xmppClient_OnSendXml(...) handler
with Sleep(160) constantly establishes no connection,
with Sleep(165) sometimes establishes a connection and sometimes not
with Sleep(190) establishing a connection is constantly successful.

It's currently no problem for me (cause it works with my little workaround on my machine so that I can test the lib.
I'm just a little interested in learning XMPP and your good lib.

Here is my connect method:

        private void Connect()
        {
            xmppClient = new XmppClient();

            xmppClient.Status = "I'm chatty";

            xmppClient.Username = "maltin1";
            xmppClient.XmppDomain = "yk8j072337";
            xmppClient.Password = "password";
            xmppClient.Hostname = "localhost";

            xmppClient.OnAuthError += new EventHandler<Matrix.Xmpp.Sasl.SaslEventArgs>(xmppClient_OnAuthError);
            xmppClient.OnXmlError += new EventHandler<Matrix.ExceptionEventArgs>(xmppClient_OnXmlError);
            xmppClient.OnError += new EventHandler<Matrix.ExceptionEventArgs>(xmppClient_OnError);
            xmppClient.OnStreamError += new EventHandler<Matrix.StreamErrorEventArgs>(xmppClient_OnStreamError);

            xmppClient.OnSendXml += new EventHandler<Matrix.TextEventArgs>(xmppClient_OnSendXml);
           
            WriteToLog("Connecting to " + xmppClient.Username + "@" + xmppClient.XmppDomain +
                       "/" + xmppClient.Resource + " ...");
                      
            xmppClient.Show = Matrix.Xmpp.Show.chat;

            xmppClient.Open();

and my handler:

        void xmppClient_OnSendXml(object sender, Matrix.TextEventArgs e)
        {
            WriteToLog("OnSendXml: " + e.ToString());
            Thread.Sleep(165);
        }


There is no time pressure on my side so just have a look on it when you feel comfortable.

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

I installed the latest Openfire version and can't cause your problems here.

Is you application a System.Windows.Forms GUI app?
If yes, have you set a Invoke Control, or invoke all events on your own which update the UI?

Alex
Avatar
martinbach #10
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

yes it's a winforms app and

yes I invoke the events on my own

e.g.

        private delegate void SetLogTextCallback(string text);

        private void WriteToChatSend(string text)
        {
            if (this.textBoxChatToSend.InvokeRequired)
            {
                this.textBoxLog.Invoke(new SetChatSendTextCallback(WriteToChatSend), text);
            }
            else
            {
                if (!string.IsNullOrEmpty(textBoxChatToSend.Text))
                {
                    this.textBoxChatToSend.Text = string.Concat(this.textBoxChatToSend.Text, Environment.NewLine);
                }

                this.textBoxChatToSend.Text += text;
                this.textBoxChatToSend.SelectionStart = this.textBoxLog.Text.Length;
                this.textBoxChatToSend.ScrollToCaret();
            }
        }

Thank you for your effort.

Martin
Avatar
Alex #11
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
can your please post your xml log without the Threading.Sleep.
Then I can see where it stops. I fixed a problem related to ejabberd servers yesterday, maybe its the same with your Openfire.

Alex
Avatar
martinbach #12
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

here is my dump without Threading.Sleep:


Connecting to maltin1@yk8j072337/MatriX ...

OnSendXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="yk8j072337" version="1.0" >
OnReceiveXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="yk8j072337" id="da6a0ae5" xml:lang="en" version="1.0" >
OnReceiveXml: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <mechanism>DIGEST-MD5</mechanism>
    <mechanism>PLAIN</mechanism>
    <mechanism>ANONYMOUS</mechanism>
    <mechanism>CRAM-MD5</mechanism>
  </mechanisms>
  <compression xmlns="http://jabber.org/features/compress">
    <method>zlib</method>
  </compression>
  <auth xmlns="http://jabber.org/features/iq-auth" />
  <register xmlns="http://jabber.org/features/iq-register" />
</stream:features>
OnSendXml: <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
OnReceiveXml: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09InlrOGowNzIzMzciLG5vbmNlPSJyRzVUS1M0VXhaWWNSeDFGUFExRjVMcjlBZGRZZ2tFNTdhZVltMnBNIixxb3A9ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz</challenge>
OnSendXml: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9Im1hbHRpbjEiLHJlYWxtPSJ5azhqMDcyMzM3Iixub25jZT0ickc1VEtTNFV4WlljUngxRlBRMUY1THI5QWRkWWdrRTU3YWVZbTJwTSIsY25vbmNlPSJmNzUxOGJjYzJhOTY0ZGUxMmE3NWVjZTI5NDQxMWU1ZDQxMzA2ZGU3YmUwY2ZiNmRkMjVmMjNjMzU3YzI3YzgyIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3lrOGowNzIzMzciLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9MzcwMDI5OWY4ZmEzZjhiMzRmNjYxMzYxN2ZiY2U2Mjg=</response>
OnReceiveXml: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cnNwYXV0aD0zMjBiOWI0ZTI3NTYyOGRlNzMwYzkxMjk4MzFhM2ZiYg==</success>
OnLogin: Matrix.EventArgs
OnSendXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="yk8j072337" version="1.0" >
OnReceiveXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="yk8j072337" id="da6a0ae5" lang="en" version="1.0" >
OnReceiveXml: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <compression xmlns="http://jabber.org/features/compress">
    <method>zlib</method>
  </compression>
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" />
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</stream:features>
OnSendXml: <iq id="MX_1" type="set" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <resource>MatriX</resource>
  </bind>
</iq>
OnReceiveXml: <iq type="result" id="MX_1" to="yk8j072337/da6a0ae5" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>maltin1@yk8j072337/MatriX</jid>
  </bind>
</iq>
OnBind: Matrix.JidEventArgs
OnSendXml: <iq id="MX_2" type="set" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>
OnSendXml: <iq id="MX_3" type="get" xmlns="jabber:client">
  <query xmlns="jabber:iq:roster" />
</iq>
OnIq: <iq type="result" id="MX_1" to="yk8j072337/da6a0ae5" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>maltin1@yk8j072337/MatriX</jid>
  </bind>
</iq>
OnReceiveXml: <iq type="result" id="MX_2" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>
OnIq: <iq type="result" id="MX_2" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>

That's it.


With Threading.Sleep(200) the dump looks like:

Connecting to maltin1@yk8j072337/MatriX ...

OnSendXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="yk8j072337" version="1.0" >
OnReceiveXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="yk8j072337" id="466a2dbc" xml:lang="en" version="1.0" >
OnReceiveXml: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
  <mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <mechanism>DIGEST-MD5</mechanism>
    <mechanism>PLAIN</mechanism>
    <mechanism>ANONYMOUS</mechanism>
    <mechanism>CRAM-MD5</mechanism>
  </mechanisms>
  <compression xmlns="http://jabber.org/features/compress">
    <method>zlib</method>
  </compression>
  <auth xmlns="http://jabber.org/features/iq-auth" />
  <register xmlns="http://jabber.org/features/iq-register" />
</stream:features>
OnSendXml: <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />
OnReceiveXml: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09InlrOGowNzIzMzciLG5vbmNlPSJpcTIvT095Z1pIcG1iZk9GcjNmMXNZT2lUa2I1TXlHVkNPMjlreitXIixxb3A9ImF1dGgiLGNoYXJzZXQ9dXRmLTgsYWxnb3JpdGhtPW1kNS1zZXNz</challenge>
OnSendXml: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9Im1hbHRpbjEiLHJlYWxtPSJ5azhqMDcyMzM3Iixub25jZT0iaXEyL09PeWdaSHBtYmZPRnIzZjFzWU9pVGtiNU15R1ZDTzI5a3orVyIsY25vbmNlPSI2YmI2ODg3NWU0NjJlZjRiNzJiZGFkMDExZjQ4NWJmNzc0ZmUzZTBlYWIyYjc3Mzg1OGJhMDM2YjM5NjhjZjVhIixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL3lrOGowNzIzMzciLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9YWU4MDJiZmFmNTY1NDQ1NTkyMGJlMDI5Y2I2OGU4NTQ=</response>
OnReceiveXml: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cnNwYXV0aD05NzdjNDc3ZDBmY2E0YTA4Y2FmZDcyYmU4NDIzZGQ0NQ==</success>
OnLogin: Matrix.EventArgs
OnSendXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" to="yk8j072337" version="1.0" >
OnReceiveXml: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="yk8j072337" id="466a2dbc" lang="en" version="1.0" >
OnReceiveXml: <stream:features xmlns:stream="http://etherx.jabber.org/streams">
  <compression xmlns="http://jabber.org/features/compress">
    <method>zlib</method>
  </compression>
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" />
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</stream:features>
OnSendXml: <iq id="MX_4" type="set" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <resource>MatriX</resource>
  </bind>
</iq>
OnReceiveXml: <stream:error xmlns:stream="http://etherx.jabber.org/streams">
  <conflict xmlns="urn:ietf:params:xml:ns:xmpp-streams" />
</stream:error>
OnReceiveXml: <iq type="result" id="MX_4" to="yk8j072337/466a2dbc" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>maltin1@yk8j072337/MatriX</jid>
  </bind>
</iq>
OnBind: Matrix.JidEventArgs
OnSendXml: <iq id="MX_5" type="set" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>
OnReceiveXml: </stream:stream>
OnSendXml: <iq id="MX_6" type="get" xmlns="jabber:client">
  <query xmlns="jabber:iq:roster" />
</iq>
OnClose: Matrix.EventArgs
OnIq: <iq type="result" id="MX_4" to="yk8j072337/466a2dbc" xmlns="jabber:client">
  <bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
    <jid>maltin1@yk8j072337/MatriX</jid>
  </bind>
</iq>
OnReceiveXml: <iq type="result" id="MX_5" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>
OnIq: <iq type="result" id="MX_5" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <session xmlns="urn:ietf:params:xml:ns:xmpp-session" />
</iq>
OnReceiveXml: <iq type="result" id="MX_6" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <query xmlns="jabber:iq:roster">
    <item jid="maltin2@yk8j072337" subscription="both" />
    <item jid="maltin" name="maltin1" ask="subscribe" subscription="none" />
  </query>
</iq>
OnIq: <iq type="result" id="MX_6" to="maltin1@yk8j072337/MatriX" xmlns="jabber:client">
  <query xmlns="jabber:iq:roster">
    <item jid="maltin2@yk8j072337" subscription="both" />
    <item jid="maltin" name="maltin1" ask="subscribe" subscription="none" />
  </query>
</iq>
OnRosterStart: Matrix.EventArgs
OnRosterItem: Matrix.Xmpp.Roster.RosterEventArgs
OnRosterItem: Matrix.Xmpp.Roster.RosterEventArgs
OnRosterEnd: Matrix.EventArgs
OnSendXml: <presence xmlns="jabber:client">
  <show>chat</show>
  <status>I'm chatty</status>
  <priority>0</priority>
</presence>


Good luck and thanks

Martin
Avatar
Alex #13
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this is exactly the same problem I had with some ejabberd servers. This is fixed in the latest version.
I have to make some more tests then I send you an update by email.

Alex
Avatar
martinbach #14
Member since Mar 2009 · 60 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

that would be great, thanks.

Martin
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: