Not logged in. · Lost password · Register
Forum: agsXMPP SDK Support RSS
Avatar
lreyero #1
Member since Dec 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Sending IQ request and response using GeoLocIq
I am developping a Jabber client supporting the GeoLoc extensions.
I use AGS XMPP SDK.

I am trying to have a client send an IQ request of type GeoLocIQ in order to ask for the location of the recipient.
Unfortunately, the server (or the recipient) returns an error. So my IQ request never reaches the recipient (or at least my code in the OnIQ event). I am stucked, and I would really need your help to figure out why this request is not sent correctly to the recipient, and why my OnIQ event is not triggered.

Here are the details:
I use this code to send the GeoLocIQ:

GeoLocIq locationRequest = new GeoLocIq();
locationRequest.Type = IqType.get;
locationRequest.From = xmpp.MyJID;
locationRequest.To = contact.Jid;
xmppClientConnection.Send(locationRequest);

Using Ethereal, I can see the following message is sent to the server:

<iq xmlns="jabber:client" id="agsXMPP_5" type="get" from="lionel.reyero@jabber.org/mobile" to="john.reyero@jabber.org">
<geoloc xmlns="http://jabber.org/protocol/geoloc" />
</iq>

It seems alright to me.
But, the server seems to automatically replies (without even forwarding the request to the remote contact):

<iq from='john.reyero@jabber.org' to='lionel.reyero@jabber.org/mobile' type='error' xml:lang='en' id='agsXMPP_5'>
<geoloc xmlns='http://jabber.org/protocol/geoloc'/>
<error code='501' type='cancel'>
<feature-not-implemented xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
</error>
</iq>

I think it is the server responding on the behalf of the remote contact, because I can't see the IQ request in the "readXML" event of the recipient. Why the server would response on the behalf of the recipient?? Why does it says the feature is not implemented, and why it should even care?? Do the clients have to declare which extensions they support ?
It is weird..

I am using jabber.org server. I have tested it on another server, but got exactly the same error.
Probably the syntaxe of the IQ request is not conform to the standards. What can i do?


I would really appreciate your help.

Thanks a lot!

Regards,

Lionel
Avatar
Alex #2
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
hello lreyero,

you don't have to use Ethereal, just use the OnReadXml and OnWriteXml events. There are also read and write events in the socket class which are more low level than the Read/Write Xml events.

You have to send IQ's always to a full Jabber ID (with resource). You sent it to john.reyero@jabber.org which is a bare Jabber Id. You have to find the resource of john.reyero@jabber.org and send the IQ to this full Jid build from user@server/resource.

You get all the resources of your contacts with the presence packets. I normally suggest to store the resources with the contact list or some other collection. If you work a lot with IQ's you always need it. Also if a contact is online with multiple clients then it's possible that you want to show also the resources to let the user decide to which resource an IQ or message is sent. Think of the case where your contact has a Mobile phone and a pocket PC, both logged in but at different locations. The mobile phone in his pocket and the pocket pc at the office on the desk.

For message stanzas there are routing rules in the xmpp core. This means a server routes also messages to bare Jid's. The server sends messages to bare Jid's to the most available resource (highest priority). This is why most people just send a message to a bare Jid and let the server decide to which resource the message is routed.

Alex
Alexander Gnauck
AG-Software
Avatar
lreyero #3
Member since Dec 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks a lot Alex,

Using a full Jid my request is now sent to the recipient successfully.

However, I have another problem:
When the request is received, and when the xmpp_OnIq event is triggered, I can't "cast" or "detect" that the incoming IQ is of type GeoLocIq. Do you see what I mean?

I have tried several way to find out if the incoming IQ is of type GeoLocIQ, but all of them have failed.
Here is a list of my attempts:

        void xmpp_OnIq(object sender, agsXMPP.Xml.Dom.Node e)
        {

                 GeoLocIq myIq = e as GeoLocIq;    //Fails: myIq is null

                 ...

                 if (e is GeoLocIq){...}     //Fails: never enter the if statements

                 ...

                 agsXMPP.protocol.client.IQ iq = e as IQ;  //Works fine
                 if (iq is GeoLocIq){...}                          //Fails: never enter the if statement    
                  ...
                 GeoLocIq myIq = (GeoLocIq)iq;              //Fails: system exception

                 GeoLoc geoloc = (GeoLoc)iq.Query;        //Fails: iq.Query is null


That's pretty much everything that I have tried.

The request is sent exactly as shown in my first message on this thread (using a complete Jid this time).

I don't know what to do...

Your help will be highly appreciated! Thanks a lot,

Regards,

Lionel
Avatar
Alex #4
Member since Feb 2003 · 4245 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello Lionel,

there is no way to cast an Iq to and Geoloc iq. This is by design of the object model in agsXMPP. When an iq is created in the factory there is no way to know which kind of iq it is.

  1. void xmpp_OnIq(object sender, agsXMPP.Xml.Dom.Node e)
  2. {
  3.     GeoLoc geo = (GeoLoc) e.SelectSingleElement(typeof(GeoLoc));
  4.     if (geo != null)
  5.     {
  6.         // its an Geoloc Iq
  7.     }
  8. }

or


  1. void xmpp_OnIq(object sender, agsXMPP.Xml.Dom.Node e)
  2. {
  3.     if (el.HasTag(typeof(GeoLoc)))
  4.     {
  5.         // its an Geoloc Iq
  6.     }
  7. }

Alex
Alexander Gnauck
AG-Software
Avatar
lreyero #5
Member since Dec 2006 · 3 posts
Group memberships: Members
Show profile · Link to this post
OK,

Thanks a lot for your quick reply, I am going to do it that way.

Lionel.
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