Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
Lilach #1
Member since Jun 2014 · 4 posts
Group memberships: Members
Show profile · Link to this post
Subject: Pub - Sub
Hi,
I created a pub-sub node using Psi (XMPP client - http://psi-im.org/),
Then I try to subscribe to it using the SDK (the code included).

when I request in Psi the Subscribers for the specific node, I get empty result:
  1. <iq from="pubsub.lilach" type="result" to="admin@lilach/Lilach" id="subscriptions2">
  2. <pubsub xmlns="http://jabber.org/protocol/pubsub">
  3. <subscriptions/>
  4. </pubsub>
  5. </iq>

I tried to take the iq from "SubscribeStanza" method and run it, and it works, it succeed to subscribe to the specific node.

What am I doing wrong?


  1. class Program
  2. {
  3.     private static XmppClient xmpp;
  4.     private static Jid jid;
  5.     private static PubSubManager pubSubManager;
  6.     private static Jid myJid;
  7.     static void Main(string[] args)
  8.     {
  9.  
  10.         Subscribe();
  11.         Console.ReadLine();
  12.     }
  13.  
  14.     private static void Subscribe()
  15.     {
  16.  
  17.         string domain = "Lilach";
  18.  
  19.         string guid = "admin" + "@" + domain;
  20.  
  21.         jid = new Jid(guid);
  22.  
  23.         xmpp = new XmppClient(jid, "yhaarA4n");
  24.        
  25.        
  26.         xmpp.Hostname = "127.0.0.1";
  27.         xmpp.Port = 5222;
  28.         xmpp.AutoPresence = false;
  29.         xmpp.AutoRoster = false;
  30.         xmpp.StartTls = false;
  31.  
  32.         xmpp.OnBeforeSasl += xmpp_OnBeforeSasl;
  33.         xmpp.OnMessage += xmpp_OnMessage;
  34.         xmpp.OnAuthError += xmpp_OnAuthError;
  35.         xmpp.OnError += xmpp_OnError;
  36.         xmpp.OnRegisterError += xmpp_OnRegisterError;
  37.         xmpp.OnRegister += xmpp_OnRegister;
  38.         xmpp.OnBindStart += xmpp_OnBindStart;
  39.         xmpp.OnBind += xmpp_OnBind;
  40.         xmpp.OnClose += xmpp_OnClose;
  41.         xmpp.OnLogin += xmpp_OnLogin;
  42.         xmpp.OnReceiveXml += xmpp_OnReceiveXml;
  43.         xmpp.OnStreamHeader += xmpp_OnStreamHeader;
  44.         xmpp.OnStreamError += xmpp_OnStreamError;
  45.         xmpp.OnStreamFeatures += xmpp_OnStreamFeatures;
  46.  
  47.  
  48.         try
  49.         {
  50.  
  51.             xmpp.Open();
  52.         }
  53.         catch (Exception)
  54.         {
  55.  
  56.         }
  57.     }
  58.  
  59.     static void xmpp_OnBind(object sender, JidEventArgs e)
  60.     {
  61.  
  62.     }
  63.  
  64.     static void xmpp_OnStreamFeatures(object sender, StanzaEventArgs e)
  65.     {
  66.        
  67.     }
  68.  
  69.     static void xmpp_OnStreamError(object sender, StreamErrorEventArgs e)
  70.     {
  71.        
  72.     }
  73.  
  74.     static void xmpp_OnStreamHeader(object sender, StanzaEventArgs e)
  75.     {
  76.  
  77.     }
  78.  
  79.     static void xmpp_OnReceiveXml(object sender, TextEventArgs e)
  80.     {
  81.        
  82.     }
  83.  
  84.     static void xmpp_OnBeforeSasl(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e)
  85.     {
  86.  
  87.     }
  88.  
  89.     static void xmpp_OnLogin(object sender, Matrix.EventArgs e)
  90.     {
  91.  
  92.         DoSubsribe();
  93.  
  94.     }
  95.  
  96.     static private async Task DoSubsribe()
  97.     {
  98.         pubSubManager = new PubSubManager(xmpp);
  99.         pubSubManager.OnEvent += pubSubManager_OnEvent;
  100.  
  101.         Iq iq = null;
  102.         try
  103.         {
  104.  
  105.             iq = pubSubManager.SubscribeStanza(new Jid("pubsub.lilach"), "testNode", jid); //change node according to live
  106.          
  107.         }
  108.         catch (Exception ex)
  109.         {
  110.             Console.WriteLine(" EX "+ex.Message);
  111.         }
  112.     }
  113.  
  114.     private static void OnSendAck(object sender, Matrix.Xmpp.StreamManagement.Ack.AckEventArgs e)
  115.     {
  116.  
  117.     }
  118.  
  119.     private static void OnFinished(object sender, IqEventArgs e)
  120.     {
  121.  
  122.     }
  123.  
  124.    
  125.     static private void OnSucceed(object sender, IqEventArgs e)
  126.     {
  127.  
  128.     }
  129.  
  130.  
  131.  
  132.     static void xmpp_OnClose(object sender, Matrix.EventArgs e)
  133.     {
  134.      
  135.     }
  136.  
  137.     static void xmpp_OnBindStart(object sender, IqEventArgs e)
  138.     {
  139.         //throw new NotImplementedException();
  140.     }
  141.  
  142.     static void xmpp_OnRegisterError(object sender, IqEventArgs e)
  143.     {
  144.         //throw new NotImplementedException();
  145.     }
  146.  
  147.     static void xmpp_OnError(object sender, ExceptionEventArgs e)
  148.     {
  149.      //   throw new NotImplementedException();
  150.     }
  151.  
  152.     static void pubSubManager_OnEvent(object sender, MessageEventArgs e)
  153.     {
  154.        
  155.     }
  156.  
  157.  
  158.     static private Jid GetJid(string guid, string domain)
  159.     {
  160.         //ask Avishay what is the format for this?
  161.         string JID_sender = guid + "@" + domain;
  162.         //string JID_sender = "admin" + "@" + "lilach";
  163.         Jid jidsender = new Jid(JID_sender);
  164.         return jidsender;
  165.     }
  166.     static void xmpp_OnRegister(object sender, Matrix.EventArgs e)
  167.     {
  168.        
  169.     }
  170.  
  171.     static void xmpp_OnAuthError(object sender, Matrix.Xmpp.Sasl.SaslEventArgs e)
  172.     {
  173.     //    throw new NotImplementedException();
  174.     }
  175.  
  176.     static void xmpp_OnMessage(object sender, MessageEventArgs e)
  177.     {
  178.         //throw new NotImplementedException();
  179.     }
  180. }
This post was edited 2 times, last on 2014-06-23, 12:04 by Alex.
Edit reason: code formatting
Avatar
Lilach #2
Member since Jun 2014 · 4 posts
Group memberships: Members
Show profile · Link to this post
there is one change in the code:

Instead of calling DoSubsribe from OnLogin:
  1. static void xmpp_OnLogin(object sender, Matrix.EventArgs e)
  2. {
  3.    //DoSubsribe();
  4. }

I Do:

  1. static void xmpp_OnBind(object sender, JidEventArgs e)
  2. {
  3.    myJid = e.Jid;
  4.    DoSubsribe();
  5. }
This post was edited on 2014-06-23, 12:00 by Alex.
Edit reason: code formatting
Avatar
Alex #3
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I suggest always to wait at least until the OnRosterEnd event. Or better until you get the first OnPresence event from the server.
In your first code the OnLogin event was way to early. This events tells you only that the authentication succeeded, but the session is still not ready.

after login there normally happens the following:
  • resource binding
  • retrieve roster
  • send own presence to the server.

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: MatriX RSS