Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
rksprst #1
Member since Oct 2010 · 8 posts
Group memberships: Members
Show profile · Link to this post
Subject: connecting to an anonymous server and sending a message
I want to replicate this code: http://github.com/collecta/java-xmpp-collecta/blob/master/…

except I want to use the agsXMPP library and C# to connect.

I've tried overriding the OnSaslStart event, with the suggestions for anonymous login - and them simply doing xmpp.Send("xml"), but it doesn't seem to work.

Here's my code as of right now. Any help would be greatly appreciated!

static void Main(string[] args)
        {
            XmppClientConnection xmpp = new XmppClientConnection("guest.collecta.com");
            xmpp.OnSaslStart += new SaslEventHandler(xmpp_OnSaslStart);
            xmpp.OnMessage += new agsXMPP.protocol.client.MessageHandler(xmpp_OnMessage);
            xmpp.OnXmppConnectionStateChanged += new XmppConnectionStateHandler(xmpp_OnXmppConnectionStateChanged);
            xmpp.OnError += new ErrorHandler(xmpp_OnError);
            xmpp.Open();

            //xmpp.OnLogin += delegate(object o) { xmpp.Send("te"); };
            //var s = xmpp.Status;

            string apiKey = "";
            string term = "amazon";
            string temp = "<pubsub xmlns='http://jabber.org/protocol/pubsub'>" +
                        "<subscribe jid='" + xmpp.MyJID + "' node='search'/>" +
                        "<options>" +
                        "<x xmlns='jabber:x:data' type='submit'>" +
                        "<field var='FORM_TYPE' type='hidden'>" +
                        "<value>http://jabber.org/protocol/pubsub#subscribe_options</value>" +
                        "</field>" +
                        "<field var='x-collecta#apikey'>" +
                        "<value>" + apiKey + "</value>" +
                        "</field>" +
                        "<field var='x-collecta#query'>" +
                        "<value>" + term + "</value>" +
                        "</field>" +
                        "</x></options>" +
                        "</pubsub>";
            xmpp.Send(temp);

           
            while (true)
            {
            }
        }

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

        static void xmpp_OnXmppConnectionStateChanged(object sender, XmppConnectionState state)
        {
            Console.WriteLine(state.ToString());
        }

        static void xmpp_OnMessage(object sender, agsXMPP.protocol.client.Message msg)
        {
            Console.WriteLine(msg.ToString());
        }

        static void xmpp_OnSaslStart(object sender, SaslEventArgs args)
        {
            args.Auto = false;
            args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.ANONYMOUS);
        }
Avatar
Alex #2
Member since Feb 2003 · 4327 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
This code looks correct and should work. I have a basic example working for MatriX. It looks similar to your code.

Alex
This post was edited on 2010-10-08, 14:48 by 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:
Forum: agsXMPP RSS