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: Hep! How to notified the presence for other users
Hi, all
I have a question related about sending presence for other computer.
Why computer 2 not see computer 1 presence?
First I modified the server (sample code):
1. In method: ProcessRosterIq(Iq iq)
  1.    if (iq.Type == IqType.get){
  2.                 iq.Type = IqType.result;
  3.             //create new roster item add to computer1
  4.                 if (User == "computer1"){
  5.                     var ri = new RosterItem { Jid = "computer2@localhost/MatriX" };
  6.                     ri.Name = "computer2";
  7.                     ri.Subscription = Subscription.both;
  8.                     iq.Query.Add(ri);
  9.                 }
  10.            //create new roster item add to computer2
  11.                 else if (User == "computer2")
  12.                 {
  13.                     var ri = new RosterItem { Jid = "computer1@localhost/MatriX" };
  14.                     ri.Name = "computer1";
  15.                     ri.Subscription = Subscription.both;
  16.                     iq.Query.Add(ri);
  17.                 }
  18.                 Send(iq);
  19.             }
2. In method streamParser_OnStreamElement(object sender, StanzaEventArgs e)
  1. if (e.Stanza is Presence)
  2.             {
  3.                 // route presences here and handle all subscription stuff
  4.                 Presence p = (Presence)e.Stanza;
  5.                 if(User == "computer1")
  6.                 {
  7.                     p.From = "computer1@localhost/MatriX";
  8.                    
  9.                     p.To = "computer2@localhost/MatriX";
  10.                 }
  11.                 else if(User == "computer2")
  12.                 {
  13.                     p.From = "computer2@localhost/MatriX";
  14.                    
  15.                     p.To = "computer1@localhost/MatriX";
  16.                 }
  17.                 Send(p);
  18.             }

After that, I start server (Sample code).
Using miniclient (samplecode) login to computer1.
Login to computer 2.
Here is the debug XML for computer 1:
  1. SEND: <presence xmlns="jabber:client">
  2.  <show>chat</show>
  3.  <status>ready for chat</status>
  4.  <priority>0</priority>
  5. </presence>
  6. RECV: <presence from="computer1@localhost/MatriX" to="computer2@localhost/MatriX" xmlns="jabber:client">
  7.  <show>chat</show>
  8.  <status>ready for chat</status>
  9.  <priority>0</priority>
  10. </presence>

Debug XML for computer 2:
  1. SEND: <presence xmlns="jabber:client">
  2.  <show>chat</show>
  3.  <status>ready for chat</status>
  4.  <priority>0</priority>
  5. </presence>
  6. RECV: <presence from="computer2@localhost/MatriX" to="computer1@localhost/MatriX" xmlns="jabber:client">
  7.  <show>chat</show>
  8.  <status>ready for chat</status>
  9.  <priority>0</priority>
  10. </presence>


It suppose in computer1 must have this debug XML:
  1. RECV: <presence from="computer2@localhost/MatriX" to="computer1@localhost/MatriX" xmlns="jabber:client">
  2.  <show>chat</show>
  3.  <status>ready for chat</status>
  4.  <priority>0</priority>
  5. </presence>

But I don't see it! Why?? Is it wrong in method send (server code)????
Note that: This is just the simple code to test presence between computer1 & computer 2.
And I am new to this XMPP. So forgive me if I am asking something wrong.

Thank you
This post was edited on 2014-03-07, 07:28 by Alex.
Edit reason: added formatting tags for code and xml
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I think the problem is that you send the presence on the wrong XmppSeverConnection object.

The server has to handle one XmppSeverConnection for each user logged in.

When computer1 one sends this presence:
  1. <presence xmlns="jabber:client">
  2.  <show>chat</show>
  3.  <status>ready for chat</status>
  4.  <priority>0</priority>
  5. </presence>

then you have to publish back this presence to all connected resources of computer1, and to all subscribed contacts of the computer1 user.

WHich means when you want to show the presence of computer1 to computer to, you have to find the XmppSeverConnections of computer2 and send the presence on this connection.

Does this answer you question?

Alex
Avatar
thuanthanh #3
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
Yes I think that is the problem. But how am I find XmppSeverConnections of computer2 and send the presence on this connection???
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
put all your connections in data connection and then find it from there with LinQ.

eg:
  1. Dictionary<Jid, XmppSeverConnections> connections;

Alex
Avatar
thuanthanh #5
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
Ok, thank for your quick reply!
Avatar
thuanthanh #6
Member since Mar 2014 · 7 posts · Location: VietNam
Group memberships: Members
Show profile · Link to this post
Ok, it work. Thank 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