Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
thuanthanh #1
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
Subject: How to update roster list from server to client
Hi, all.
I have a question about using roster push https://xmpp.org/rfcs/rfc6121.html
First, I modified a little bit in server(sample code)
  1. private void ProcessRosterIq(Iq iq)
  2.         {
  3.             if (iq.Type == IqType.get)
  4.             {               
  5.                 iq.Type = IqType.result;                   
  6.                 //Find the other user in dictionary
  7.                 foreach (KeyValuePair<Jid, clsXmppSeverConnection> pair in clsGlobalXMPP.MPPConnection)
  8.                 {
  9.                     Jid jid = new Jid(pair.Key);
  10.                     if (jid.User != User) //if it is not current user
  11.                     {
  12.                         var ri = new RosterItem { Jid = jid };
  13.                         ri.Name = jid.User;
  14.                         iq.Query.Add(ri); //add previous user into iq
  15.  
  16.                         Guid g = new Guid();
  17.                         Jid item = new Jid(User, XmppDomain, Resource);
  18.                         //using rouster push to send information about new user to previous login user
  19.                         string strXML = "<iq id='"+g.ToString()+"'"+
  20.                                         "to='"+jid+"'"+
  21.                                         "type='set'>"+
  22.                                         "<query xmlns='jabber:iq:roster'>"+
  23.                                         "<item jid='"+item+"'/>" +
  24.                                         "</query>" +
  25.                                         "</iq>";
  26.  
  27.                         XElement ele = XElement.Parse(strXML);
  28.                         XmppXElement myelement = new XmppXElement(ele);
  29.                         //get connection
  30.                         clsXmppSeverConnection connection = pair.Value;
  31.                         connection.Send(myelement); //send iq query to client
  32.  
  33.                     }
  34.                 }
  35.                 Send(iq);
  36.             }
  37.         }
The problem here: it was not running.
I login computer1 first. Next, I login with user: computer 2.
Here is debug XML in computer 2. It stuck on send iq.
  1. SEND: <iq id="MX_2" type="get" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:roster" />
  3. </iq>

Are there any method that make server send notification to client. (like a new user add to your contact or something else???)
Avatar
thuanthanh #2
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
I update this code using RosterIq (matrix)
  1. private void ProcessRosterIq(Iq iq)
  2.         {
  3.             if (iq.Type == IqType.get)
  4.             {
  5.                
  6.                 iq.Type = IqType.result;   
  7.  
  8.                
  9.                 //Find the other user in dictionary & add to route item
  10.                 foreach (KeyValuePair<Jid, clsXmppSeverConnection> pair in clsGlobalXMPP.MPPConnection)
  11.                 {
  12.                     Jid jid = new Jid(pair.Key);
  13.                     if (jid.User != User)
  14.                     {
  15.                         var ri = new RosterItem { Jid = jid };
  16.                         ri.Name = jid.User;
  17.                         iq.Query.Add(ri);
  18.                         RosterIq item = new RosterIq(jid,new Jid(User, XmppDomain, Resource),  IqType.set);
  19.                         item.Query.Add(new Jid(User, XmppDomain, Resource));
  20.                         clsXmppSeverConnection connection = pair.Value;
  21.                         connection.Send(item);
  22.                     }
  23.                 }               
  24.                 //query to get user from database:
  25.                 Send(iq);
  26.             }

this time, it does send information to client but client still don't add roster into contact list
  1. RECV: <iq id="MX_3" to="computer1@localhost/VNYI" from="computer2@localhost/VNYI" type="set" xmlns="jabber:client">
  2.  <query xmlns="jabber:iq:roster">computer2@localhost/VNYI</query>
  3. </iq>
  4. SEND: <iq type="result" id="MX_3" xmlns="jabber:client" />

What did I do wrong????
Avatar
Alex #3
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
you are mixing lots of stuff here.

in your code you process a Roster get request. That is a request from a client to get the complete contact list on login.

1) You have to reply to a get request with result or error. You reply with IqType.set which is wrong.
2) your RosterIq payload is totally wrong. Below is a code snippet how you build it correct.

  1. RosterIq riq = new RosterIq {Type = Matrix.Xmpp.IqType.result};
  2. iq.Roster.AddRosterItem(new RosterItem {Jid = "alex@server.com", Name = "Alex"});

This code is also present in the original server example. Why you did not use the original code and modify it?

Roster pushes are something totally different. They get sent when a client adds new contacts during a XMPP session.

Alex
Avatar
thuanthanh #4
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
Thanks, Alex! It work
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