Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
phrankster #1
Member since Aug 2007 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Trouble logging in with agsXMPP
I am trying to connect to an openfire server using the following code, however I am unable to authenticate. I am a newbie at this, so if anyone could provide some assistance (code revisions even), that would be greatly appreciated. I simply need to create a basic IM application that performs a send-only notification to users set up on the openfire server.

XmppClientConnection xmpp = new XmppClientConnection();

            xmpp.Server = "openfireserver";
            xmpp.Username = "myuserid@openfireserver";
            xmpp.Password = "mypassword";
            xmpp.Open();
           
            agsXMPP.Jid JID = new Jid("sendtouser@openfireserver");

            agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
            msg.Type = agsXMPP.protocol.client.MessageType.chat;
            msg.To = JID;
            msg.Body = "This is a test " + DateTime.Now.ToString();

            xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
            Console.ReadKey();

When I run the application, I receive the following to my console screen:

Cipher: Rc4 strength 128
Hash: Md5 strength 128
Key exchange: RsaSign strength 1024
Protocol: Tls
Is authenticated: True as server? False
IsSigned: True
Is Encrypted: True
Certificate revocation list checked: True
Remote cert was issued to CN=openfireserver and is valid from 8/28/2007 2:53:13 PM until
8/1/2012 2:53:13 PM.
Can read: True, write True
Can timeout: True
0605a1fc7053bf3930b1355c5ab33aeb

Thanks in advance!
Avatar
Jabberer #2
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
your username is wrong. The username must not contain the xmpp domain (@openfireserver).

The correct username is: myuserid

Take also a look at the MiniClient example. This is a complete basic chat client.
Software Developer
AG-Software
Avatar
phrankster #3
Member since Aug 2007 · 5 posts
Group memberships: Members
Show profile · Link to this post
Thanks for your reply. Unfortunately after changing the user ID, I am still not able to establish a connection to the openfire server -- same results. The MiniClient example connects just fine though, so something is still incorrect in my code. I have tried to work my way through the MiniClient code, however I am not familiar enough with XMPP enough yet that it doesn't make much sense to me. Any other thoughts to help resolve this?

Thanks again.
Avatar
Alex #4
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the code looks correct to me.
Can you please post your Xml log?

Alex
Alexander Gnauck
AG-Software
Avatar
phrankster #5
Member since Aug 2007 · 5 posts
Group memberships: Members
Show profile · Link to this post
After enabling XML logging I was able to figure out how to get the authentication working. However, I am now dealing with another issue that I hope to resolve. According to the XML, it looks like it is generating the chat message, however the remote side is not receiving it. I noticed an error 501 in the XML (highlighted orange) which may have to do with this issue.

This is what my XML looks like when I execute the application:

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="openfireserver" version="1.0" xml:lang="en" id="b548896b" >

RECV XML: <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></com
pression><auth xmlns="http://jabber.org/features/iq-auth" /><register xmlns="http://jabber.org/features/iq-register"/></stream:features>

SEND XML: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />

RECV XML: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />

Cipher: Rc4 strength 128
Hash: Md5 strength 128
Key exchange: RsaSign strength 1024
Protocol: Tls
Is authenticated: True as server? False
IsSigned: True
Is Encrypted: True
Certificate revocation list checked: True
Remote cert was issued to CN=openfireserver and is valid from 8/28/2007 2:53:13 PM until
8/1/2012 2:53:13 PM.
Can read: True, write True
Can timeout: True

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="openfireserver" version="1.0" xml:lang="en" id="b548896b" >

RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><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>

SEND XML: <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"/>

RECV XML: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09ImdvbWVyIi
xub25jZT0iMHpoUEdHRklsbjl1NmJoSEo0OTdiLzRNTDVTWTJWNzRjUzMxTDBLdCIscW9wPSJhdXRoIi
xjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==</challenge>529717e190c26f5cef86268f04669e34

SEND XML: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9InBvYyI
scmVhbG09ImdvbWVyIixub25jZT0iMHpoUEdHRklsbjl1NmJoSEo0OTdiLzRNTDVTWTJWNzRjUzMxTDB
LdCIsY25vbmNlPSJhMTg5MjZmM2ViYjlhNDQ1MTkwNGQ0Y2EyMTU3NjgzMTBhMTY4NzQ0YTQ4NGFhZDZ
mMmE3MTQ4NDBlZWM5NjE1IixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL2dvbWV
yIixjaGFyc2V0PXV0Zi04LHJlc3BvbnNlPTM4MWQ5ZmI1Nzc3ZDZmOTE2ZTc3YzI2N2E0N2RlNTky</response>

RECV XML: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cnNwYXV0aD1lMDc0M2M4ZDc1YjNiMzJjOWQ2ODllYTk1NDM2NTM5MQ==</success>

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' xml:lang='en'>

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="openfireserver" version="1.0" xml:lang="en" id="b548896b" >

RECV XML: <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>

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_1" type="set" to="openfireserver"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>TestIM</resource></bind></iq>

RECV XML: <iq xmlns="jabber:client" from="openfireserver" to="openfireserver/b548896b" type="result" id="agsXMPP_1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>myuserid@openfireserver/TestIM</jid></bind></iq>

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_2" type="set" to="openfireserver"><session xmlns="urn:ietf:params:xml:ns:xmpp-session" /></iq>

RECV XML: <iq xmlns="jabber:client" from="openfireserver" to="myuserid@openfireserver/TestIM" type="result" id="agsXMPP_2"><session xmlns="urn:ietf:params:xml:ns:xmpp-session" /></iq>

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_3" type="get" to="openfireserver"><query xmlns="jabber:iq:agents" /></iq>

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_4" type="get"><query xmlns="jabber:iq:roster" /></iq>

RECV XML: <iq xmlns="jabber:client" from="openfireserver" to="myuserid@openfireserver/TestIM" type="error" id="agsXMPP_3"><query xmlns="jabber:iq:agents" /><error code="501" type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>

RECV XML: <iq xmlns="jabber:client" to="myuserid@openfireserver/TestIM" type="result" id="agsXMPP_4"><query xmlns="jabber:iq:roster" /></iq>

SEND XML: <message xmlns="jabber:client" type="chat" to="sendtouser@openfireserver"><body>This is a test 8/29/2007 12:35:47 PM</body></message>

Here's my revised code that generates the above XML output:

            XmppClientConnection xmpp = new XmppClientConnection();

            xmpp.Server = "openfireserver";
            xmpp.Port = 5222;
            xmpp.UseSSL = false;
            xmpp.Resource = "TestIM";
            xmpp.ConnectServer = "openfireserver";
            xmpp.Username = "myuserid";
            xmpp.Password = "mypassword";
            xmpp.Priority = 10;
            xmpp.Status = "Online";
            xmpp.UseCompression = false;
            xmpp.AutoRoster = true;
            xmpp.Show = ShowType.chat;
            xmpp.OnReadXml += new XmlHandler(xmpp_OnReadXml);
            xmpp.OnWriteXml += new XmlHandler(xmpp_OnWriteXml);
            xmpp.OnError += new ErrorHandler(xmpp_OnError);

            try
            {
                xmpp.Open();
                Thread.Sleep(TimeSpan.FromSeconds(5));
            }

            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                agsXMPP.Jid JID = new Jid("sendtouser@openfireserver");
                agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();
                msg.Type = agsXMPP.protocol.client.MessageType.chat;
                msg.To = JID;
                msg.Body = "This is a test " + DateTime.Now.ToString();

                //xmpp.OnLogin += delegate(object o) { xmpp.Send(msg); };
                xmpp.Send(msg);

                Console.WriteLine("\nEnd of Application!");
                Console.ReadKey();
            }
        }

        private static void xmpp_OnError(object sender, Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        private static void xmpp_OnReadXml(object sender, string xml)
        {
            Console.WriteLine("\nRECV XML: " + xml);
        }

        private static void xmpp_OnWriteXml(object sender, string xml)
        {
            Console.WriteLine("\nSEND XML: " + xml);
        }

Thanks for any assistance that can be provided.
Avatar
Alex #6
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

You can ignore the error in the log. The libs requests the agents by default (AutoAgents = true) which is not supported by Openfire.
Did your other client send the presence to the server? If you send no presence to the server you will never receive a message.

Alex
Alexander Gnauck
AG-Software
Avatar
phrankster #7
Member since Aug 2007 · 5 posts
Group memberships: Members
Show profile · Link to this post
The MiniClient is able to send/receive presence, as shown here:

SEND: <presence xmlns="jabber:client"><status /><priority>1</priority></presence>
RECV: <presence xmlns="jabber:client" from="gtalk.openfireserver" to="myuserid@openfireserver" />
RECV: <presence xmlns="jabber:client" from="myuserid\40gmail.com@gtalk.openfireserver" to="myuserid@openfireserver" />

When I run the MiniClient and then execute my C# application, my application is able to send just fine. But when I close down the MiniClient, I am not able to send messages. I am definitely missing something here.
Avatar
Alex #8
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
sorry but i think i don't understand your problem.
Is your code running on both sides, sender and receiver?
Or do you run your code only on one side and the MiniClient on the other side?

Alex
Alexander Gnauck
AG-Software
Avatar
phrankster #9
Member since Aug 2007 · 5 posts
Group memberships: Members
Show profile · Link to this post
Alex,

I apologize for the confusion. My application is running as the sender and the openfire server is running as the receiver, which then routes to the appropriate messaging gateway. I am only testing with MiniClient, but not using it as a dependency with my application.

After reading through several posts, apparently I am missing a call to SendMyPresence(). I am able to see the presence data in my XML output now, so I believe that is fixed. I have added a segment to the code that sends the presence when the OnLogin event is called. I am, however still unable to receive messages.

    private static void xmpp_OnLogin(object sender)
       {

         xmpp.SendMyPresence();
         xmpp.Status = "Online";
         xmpp.Show = ShowType.chat;

         agsXMPP.protocol.client.Message msg = new agsXMPP.protocol.client.Message();

         msg.Type = agsXMPP.protocol.client.MessageType.chat;
         msg.To = new Jid("sendtouser@openfireserver");
         msg.Body = "This is a test " + DateTime.Now.ToString();
    
         xmpp.Send(msg);

         Console.WriteLine("\nEnd of Application!");

         xmpp.Close();
         Console.ReadKey();
      }

Here's my new XML output:

OnXmppConnectionStateChanged: Connecting
OnXmppConnectionStateChanged: Connected

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://e
therx.jabber.org/streams' version='1.0' xml:lang='en'>

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="
openfireserver" version="1.0" xml:lang="en" id="21882b60" >

RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><star
ttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" /><mechanisms xmlns="urn:ietf:param
s:xml:ns:xmpp-sasl"><mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism
><mechanism>ANONYMOUS</mechanism><mechanism>CRAM-MD5</mechanism></mechanisms><co
mpression xmlns="http://jabber.org/features/compress"><method>zlib</method></com
pression><auth xmlns="http://jabber.org/features/iq-auth" /><register xmlns="htt
p://jabber.org/features/iq-register" /></stream:features>

OnXmppConnectionStateChanged: Securing

SEND XML: <starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls" />

RECV XML: <proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls" />
Cipher: Rc4 strength 128
Hash: Md5 strength 128
Key exchange: RsaSign strength 1024
Protocol: Tls
Is authenticated: True as server? False
IsSigned: True
Is Encrypted: True
Certificate revocation list checked: True
Remote cert was issued to CN=openfireserver and is valid from 8/28/2007 2:53:13 PM until
8/1/2012 2:53:13 PM.
Can read: True, write True
Can timeout: True

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://e
therx.jabber.org/streams' version='1.0' xml:lang='en'>

OnXmppConnectionStateChanged: Authenticating

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from=
openfireserver" version="1.0" xml:lang="en" id="21882b60" >

RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><mech
anisms 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:feat
ures>

SEND XML: <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5"
/>

RECV XML: <challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cmVhbG09ImdvbWVyIi
xub25jZT0iRTdyR21sL1lJbUJsVllrVW1LZGVpWTBDaHBGQWJHK3N3UVpONnBIZyIscW9wPSJhdXRoIi
xjaGFyc2V0PXV0Zi04LGFsZ29yaXRobT1tZDUtc2Vzcw==</challenge>
8074c48547734bbc983d5d98ee553502

SEND XML: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9InBvYyI
scmVhbG09ImdvbWVyIixub25jZT0iRTdyR21sL1lJbUJsVllrVW1LZGVpWTBDaHBGQWJHK3N3UVpONnB
IZyIsY25vbmNlPSJhZWU1ZDRlMDBjODljZjljMTE1YzA5NDY3OTg0Yzg0OTgxZTc3NzFkMTUzNjUyOWY
zMTI3NDM3ZmQ2ZjlkN2E1IixuYz0wMDAwMDAwMSxxb3A9YXV0aCxkaWdlc3QtdXJpPSJ4bXBwL2dvbWV
yIixjaGFyc2V0PXV0Zi04LHJlc3BvbnNlPWNhY2I5MGE4YzNiNGUzNTM5MDNhYWY0YzdhMGNhY2Mw</r
esponse>

RECV XML: <success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">cnNwYXV0aD04ZjExMzE0
MjMyOWUzMDYyNTRiOTYzODExMzY2YWYxZA==</success>

OnXmppConnectionStateChanged: Authenticated

SEND XML: <stream:stream to='openfireserver' xmlns='jabber:client' xmlns:stream='http://e
therx.jabber.org/streams' version='1.0' xml:lang='en'>

RECV XML: <stream:stream xmlns:stream="http://etherx.jabber.org/streams" from="
openfireserver" version="1.0" xml:lang="en" id="21882b60" >

RECV XML: <stream:features xmlns:stream="http://etherx.jabber.org/streams"><comp
ression xmlns="http://jabber.org/features/compress"><method>zlib</method></compr
ession><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind" /><session xmlns="urn:ietf
:params:xml:ns:xmpp-session" /></stream:features>

OnXmppConnectionStateChanged: Binding

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_1" type="set" to="openfireserver"><bind x
mlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>IMtest</resource></bind></iq>

RECV XML: <iq xmlns="jabber:client" from="openfireserver" to="openfireserver/21882b60" type="resul
t" id="agsXMPP_1"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>myuserid@openfireserver/
IMtest</jid></bind></iq>

OnXmppConnectionStateChanged: Binded
OnXmppConnectionStateChanged: StartSession

SEND XML: <iq xmlns="jabber:client" id="agsXMPP_2" type="set" to="openfireserver"><sessio
n xmlns="urn:ietf:params:xml:ns:xmpp-session" /></iq>

RECV XML: <iq xmlns="jabber:client" from="openfireserver" to="myuserid@openfireserver/IMtest" type="result
" id="agsXMPP_2"><session xmlns="urn:ietf:params:xml:ns:xmpp-session" /></iq>

OnXmppConnectionStateChanged: SessionStarted

SEND XML: <presence xmlns="jabber:client"><status /><priority>10</priority></pre
sence>

SEND XML: <message xmlns="jabber:client" type="chat" to="sendtouser@openfireserver"><body>Th
is is a test 8/30/2007 10:03:44 AM</body></message>

End of Application!

SEND XML: </stream:stream>

I am running this code in a console window using debug mode; is this possibly an issue? If so, are there any workarounds? Any additional assistance you can provide is greatly appreciated.
Avatar
Alex #10
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your code and the debug looks OK. It shouldn't matter whether you send your presence or not.
If you send a message after successful authentication the server must route it.
Is it possible that something is wrong with your server configuration, gateway or the OpenFire server itself?

The only difference to the MiniClient is that it requests the roster before sending the own presence.

Can you try to set AutoRoster = true and put the code which you have in the OnLogin Event to the OnRosterEnd event?

Alex
Alexander Gnauck
AG-Software
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 SDK Support RSS