Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
smuggyuk #1
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Help with PubSub and agsXmpp
Hi there,

I'm trying to use agsXmpp to help me capture some PubSub events but can't quite get me head around how it should work as I can't find an example in the download.  I've successfully been able to trap normal messages up to now, but not PubSub events.  I then realised there was the PubSub manager!  So, once I've created the xmpp connection in the onlogin event I'm assuming I then need to create the PubSubManager, referencing the xmpp client.  So far I've got:

    void xmpp_OnLogin(object sender)
    {
        PubSubManager psm = new PubSubManager(xmpp);
        psm.Subscribe(new Jid("user@gmail.com"), new Jid("user@gmail.com"), "pubsub-node", new IqCB(processEvent));
    }

     void processEvent(object sender, IQ iq, object data)
     {
         //what goes here?  is this right?
     }

Am I on the right lines?  Has anybody got a small snippet of sample code for reading a pubsub event they could post so I know I'm heading in the right direction?  This is just for a small hobby project, so any help gratefully accepted!

Many thanks
Avatar
Alex #2
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
the PubsubManager gives you methods to create, manage and subscribe to pubsub nodes.
Once you are subscribed to a node you get the notifications with the payloads in OnMessage events.

Alex
Alexander Gnauck
AG-Software
Avatar
smuggyuk #3
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

Thanks for the advice that the events come through the OnMessage.  However, I'm still having some problems.  I can get the script below to receive messages perfectly, and it writes them into the output.txt file no bother, but the pubsub event messages don't appear to fire OnMessage, and so I don't get them in the output file.  I know the pubsub event is definatly being sent, as I can see this in the PSI xml console:

<message from="radio1@hug.hellomatty.com" to="user@gmail.com/SHEMPCRILEA4CC1F28" >
<event xmlns="http://jabber.org/protocol/pubsub#event">
<items node="http://jabber.org/protocol/tune" >
<item id="1193413" >
<tune xmlns="http://jabber.org/protocol/tune">
<artist>Sam Sparro</artist>
<title>Black And Gold</title>
</tune>
</item>
</items>
</event>
</message>

Can you review my code below and let me know where I'm going wrong, I'm assuming the OnMessage event isn't firing for the above pubsub event messages as I've not fulfilled some criteria for agsxmpp to think it is subscribed to them?  Once again many thanks for any help offered...

XmppClientConnection xmpp = new XmppClientConnection();

protected void Page_Load(object sender, EventArgs e)
{
    xmpp.AutoPresence = true;
    xmpp.AutoResolveConnectServer = true;
    xmpp.ConnectServer = "hug.hellomatty.com";
    xmpp.Server = "gmail.com";
    xmpp.Username = "user";
    xmpp.Password = "pwd";
    xmpp.OnLogin += delegate(object o) {
        xmpp.OnMessage += delegate(object b, agsXMPP.protocol.client.Message msg)
        {
            StreamWriter sr = File.AppendText(Server.MapPath("/nowplaying/xmpp/output.txt"));
            sr.WriteLine(msg.ToString());  //just dump entire message into file for now.
            sr.Close();  //close file
            xmpp.Send(new Message("chris@cgriley.com", MessageType.chat, "Finished onmessage."));  //send a message to a contact on our roster to let us know we've received a message
        };
        PubSubManager psm = new PubSubManager(xmpp);
        psm.Subscribe(new Jid("user@gmail.com"), new Jid("radio1@hug.hellomatty.com"), "http://jabber.org/protocol/tune");
        xmpp.Send(new Message("chris@cgriley.com", MessageType.chat, "Hey, waiting...."));  //now we've setup our event delegates let a contact know the script is ready
    };
    xmpp.Open();
}
Avatar
Alex #4
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
please catch the OnReadXml and OnWriteXml events for getting the debug info. If the message comes through it will be in the debug data, and I see no reason why it should not raise the OnMessage event.

In your debug I see a gmail Is. Are you using the Google XMPP servers fr your tests? If yes then please try another server, because many features are still missing in the Google XMPP servers, and the behave different than all other XMPP servers in some scenarios.

Alex
Alexander Gnauck
AG-Software
Avatar
smuggyuk #5
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

Thanks for your help, I appreciate you taking the time out to answer my questions.

I've taken on board your last post and have registered an account on the server that is issuing the pubsub event, and have now connected to the server using that.  That removes the Gmail servers from the problem.  I've also setup the OnReadXML event to debug incoming messages.  However, I'm still seeing the same behavior, my script will capture to the debug file presence updates and messages that I send, but the pubsub event message (the only thing I'm trying to capture!) isn't anywhere to be seen in the debug file (but I do see in the PSI XML console), it didn't even raise the OnReadXML event.  So, a couple of questions:

Am I definitely using the PubSubManager correctly in my code above?
Do I actually need to be subscribed to the pubsub messages for them to fire the OnReadXML event in agsxmpp?  Or is there simply some problem with the basic way the message is formed that means agsxmpp always drops them?  Hence I included a version of the message in my previous reply.

Many thanks again, I'm new to pubsub and appreciate your patience if my questions are a bit simplistic!
Avatar
Alex #6
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello,

if they are not in the OnReadXml event then the messages don't get sent to this user. agsXMPP does not drop packets.

  • You must be subscribed to the pubsub node to get the pubsub events/messages
  • did you login with Psi with the user account?
  • If yes, is it possible that you are subscribed to a full jid and login with a different resource in Psi and agsXMPP?

Alex
Alexander Gnauck
AG-Software
Avatar
smuggyuk #7
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

Thanks for your quick response, I don't quite follow though.  Could you explain your first and last point a bit more (possibly with a couple of quick examples based on the info I've already provided?  For example is the node "http://jabber.org/protocol/tune" correct to subscribe to?  As for the second point, yes I had logged in to PSI with the same user account.

Thanks!
Avatar
Alex #8
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I think what you are looking for is Personal Eventing via Pubsub http://www.xmpp.org/extensions/xep-0163.html

See section 4 Receiving Event Notifications: http://www.xmpp.org/extensions/xep-0163.html#notify

Alex
Alexander Gnauck
AG-Software
Avatar
smuggyuk #9
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Thanks for that Alex, I've had a quick look and I think I need a good night's sleep and a fresh set of eyes to take that in properly!
Avatar
Alex #10
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
ok, let me know when you have any questions after reading the documents I posted.

Alex
Alexander Gnauck
AG-Software
Avatar
smuggyuk #11
Member since Jun 2008 · 6 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,

It works!  After reading through the documents this morning and taking in who the subscriber, to and from were in relation to the Subscribe method of the PubSubManager I realised I had made the rookie mistake of getting my subscriber/from/to Jids the wrong way around. Once I updated that it was working like a charm!

So for the benefit of others who may have been following, or have stubmled accross this thread, to subscribe do:
PubSubManager psm = new PubSubManager(xmpp);
//psm.Subscribe(To, From, Subscribe, Node)
psm.Subscribe(new Jid("publisher@somejabberserver.com"), new Jid("yourlogin@somejabberserver.com"), new Jid("yourlogin@sommerjabberserver.com"), "http://jabber.org/protocol/tune");  //in this case the node is http://jabber.org/protocol/tune as this was the name of the node in the event I was capturing.

Thanks again for your help in pointing me in the right direction Alex, a what an excellent SDK, this has made tackling XMPP in my .net app so much easier than it could have been!
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