Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
roymanish1982 #1
Member since Mar 2011 · 20 posts
Group memberships: Members
Show profile · Link to this post
Subject: Unable to Request Rosters
Hi,

I am creating a Chat Application (Client and Server) using MatriX SDK.

I have create a Server wich will handle the Request From Client , i am facing an issue ,

when it try to Request Rosters using Asynchronous Iq Filter . it seems that i am not able to get the proper responce form my server.

Or i did any thin wrong in calling.

private void button2_Click(object sender, System.EventArgs e)
        {
            xmppClient.IqFilter.SendIq(ri, RosterResponse);
        }

        private void RosterResponse(object sender, IqEventArgs e)
        {
            var iq = e.Iq;

            if(iq.Type == IqType.result)
            {
                //var r = Iq.Query as Matrix.Xmpp.Roster.Roster;
                //foreach(RosterItem ri in r.GetRoster())
                //    OnRosterItem(this, new RosterEventArgs(ri));
            }
            else if(iq.Type == IqType.error)
            {
                // process errors here
            }
        }


Server Code.

void streamParser_OnStreamElement(object sender, StanzaEventArgs e)
        {
            Console.WriteLine("OnStreamElement: " + e.ToString());
            DisplayData(e.Stanza.ToString());
            if(e.Stanza.Name.LocalName == "Presence".ToLower())
            {
                // route presences here and handle all subscription stuff
            }
            else if(e.GetType() == typeof(Message))
            {
                // route the messages here
                ProcessMessages(e.Stanza as Message);
            }
            else if(e.Stanza.Name.LocalName == "Iq".ToLower())
            {
                ////ProcessIQ(e.Stanza as Iq);
               
                System.Collections.Generic.List<RosterItem> items = new System.Collections.Generic.List<RosterItem>();
                items.Add(new RosterItem()
                {
                    Jid = "manish.roy@quipment.in",
                    Name = "Manish Roy",
                    Subscription = Subscription.both,
                  
                });
                items.Add(new RosterItem()
                {
                    Jid = "rajesh.dabhi@quipment.in",
                    Name = "Rajesh Dabhi",
                    Subscription = Subscription.both
                });
                items.Add(new RosterItem()
                {
                    Jid = "chaitanya.doshi@quipment.in",
                    Name = "Chaitanya Doshi",
                    Subscription = Subscription.both
                });
                Iq iq = new Iq();
                iq.Id = e.Stanza.FirstAttribute.Value;
                iq.Type = IqType.result;
                iq.To = "manish.roy@quipment.nl";
                iq.Add(items);
                Send(iq.ToString());
            }
        }



XML Output

SEND:
<iq id="MX_1" type="get" xmlns="jabber:client">
  <query xmlns="jabber:iq:roster" />
</iq>

RECV:
<iq id="MX_1" type="result" to="manish.roy@quipment.nl" xmlns="jabber:component:accept">
  <item jid="manish.roy@quipment.in" name="Manish Roy" subscription="both" xmlns="jabber:iq:roster" />
  <item jid="rajesh.dabhi@quipment.in" name="Rajesh Dabhi" subscription="both" xmlns="jabber:iq:roster" />
  <item jid="chaitanya.doshi@quipment.in" name="Chaitanya Doshi" subscription="both" xmlns="jabber:iq:roster" />
</iq>

This post was edited on 2011-05-12, 08:47 by roymanish1982.
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your server is using the wrong iq class. You use the Iq for component streams instead of the Iq for client Streams.
Use MatriX.Xmpp.Client.Iq class and it should work.


Another small hint, instead of:

  1. else if(e.Stanza.Name.LocalName == "Iq".ToLower()) {

do
  1. else if(e.Stanza is MatriX.Xmpp.Client.Iq) {

and do
  1. Send(iq)
instead of
  1. Send(iq.ToString())

Alex
Avatar
roymanish1982 #3
Member since Mar 2011 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex
but my send accept string , and i have copied it for agsXMPP server sample.
what should be the parameter type "Object" or IQ and this is the Generic send method used for send data to client.

or is there any new way to send data using MatriX SDK.



private void Send(string data)
        {
            // Convert the string data to byte data using ASCII encoding.
            byte[] byteData = Encoding.UTF8.GetBytes(data);

            // Begin sending the data to the remote device.
            m_Sock.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), null);
        }
This post was edited on 2011-05-12, 10:55 by roymanish1982.
Avatar
Alex #4
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
no thats fine, you are right. But you should use

  1. Send(iq.ToString(false));

the false parameters does not indent the Xml which is recommended and saves also some bandwidth.

Alex
Avatar
roymanish1982 #5
Member since Mar 2011 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thnaks Again ... but i need some more help ....
in
private void button2_Click(object sender, System.EventArgs e)
        {
            Matrix.Xmpp.Client.RosterIq ri = new RosterIq(IqType.get);
            xmppClient.IqFilter.SendIq(ri, RosterResponse);
        }

       private void RosterResponse(object sender, IqEventArgs e)
        {
            var iq = e.Iq;

            if(iq.Type == IqType.result)
            {
                ////var result = iq.Element<Jid>();
 
                   
                //var r = Iq.Query as Matrix.Xmpp.Roster.Roster;
                //foreach(RosterItem ri in result.GetRoster())
                //    xmppClient_OnRosterItem(this, new RosterEventArgs(ri));
"How will i get the detials from iq , coz my iq.Query is null "

            }
            else if(iq.Type == IqType.error)
            {
                // process errors here
            }
        }


iq has

<iq id="MX_1" type="result" to="manish.roy@quipment.nl" xmlns="jabber:client">
  <item jid="manish.roy@quipment.in" name="Manish Roy" subscription="both" xmlns="jabber:iq:roster" />
  <item jid="rajesh.dabhi@quipment.in" name="Rajesh Dabhi" subscription="both" xmlns="jabber:iq:roster" />
  <item jid="chaitanya.doshi@quipment.in" name="Chaitanya Doshi" subscription="both" xmlns="jabber:iq:roster" />
</iq>

and the Output which is in Tutorial http://www.ag-software.net/matrix-xmpp-sdk/matrix-develope…

<!-- Server response -->
<iq id='rg1' to='juliet@example.com/chamber' type='result'>
    <query xmlns='jabber:iq:roster' ver='ver7'>
        <item jid='nurse@example.com'/>
        <item jid='romeo@example.net'/>
    </query>
</iq>

My Server Code to Responce Roster is

  else if(e.Stanza is Matrix.Xmpp.Client.Iq)
            {
                ////ProcessIQ(e.Stanza as Iq);
               
                System.Collections.Generic.List<RosterItem> items = new System.Collections.Generic.List<RosterItem>();
                items.Add(new RosterItem()
                {
                    Jid = "manish.roy@quipment.in",
                    Name = "Manish Roy",
                    Subscription = Subscription.both,
                  
                });
                items.Add(new RosterItem()
                {
                    Jid = "rajesh.dabhi@quipment.in",
                    Name = "Rajesh Dabhi",
                    Subscription = Subscription.both
                });
                items.Add(new RosterItem()
                {
                    Jid = "chaitanya.doshi@quipment.in",
                    Name = "Chaitanya Doshi",
                    Subscription = Subscription.both
                });

                Matrix.Xmpp.Client.RosterIq iq = new Matrix.Xmpp.Client.RosterIq();
                iq.Id = e.Stanza.FirstAttribute.Value;
                iq.Type = IqType.result;
                iq.To = "manish.roy@quipment.nl";
                iq.Add(items);
                Send(iq.ToString(false));

is there anything wrong i am doing ?
Avatar
Alex #6
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your server is sending the roster wrong.
All items must be included in a query tag.

  1. <query xmlns='jabber:iq:roster'>
  2.    <item jid='...'/>
  3.    <item jid='...'/>
  4. </query>

I suggest to use the RosterIq class to build the roster on your server.

Example:
  1. var riq = new Matrix.Xmpp.Client.RosterIq {Type = Matrix.Xmpp.IqType.result, Id = "XY", To = "user@host"};
  2. riq.Roster.AddRosterItem(new RosterItem {Name = "Alex", Jid = "alex@host"});

Alex
Avatar
roymanish1982 #7
Member since Mar 2011 · 20 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex , now i can Display all the Roster items in my list , Thanks A lots  :-D
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