Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Should I add resource id always when requesting presence for other accounts?
Avatar
jhuerta #1
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: Is the resource needed when sending "subscribe"?
Hi,

Im able to 2 register 2 accounts. This account has either the resource I choose, or agsXMPP by default.

I want to subscribe the presence from one account to the other. Should I specify the resource?


<presence xmlns="jabber:client" type="subscribe" to="tstUser@jabberdomain/resourceTest" id="123 />
[b]or [/b]
<presence xmlns="jabber:client" type="subscribe" to="tstUser@jabberdomain" id="123 />

For what I experienced, IT IS NEEDED. Otherwise, the account that I want to subscribe is not able to receive/handle the request.

The question is:

If Im registering an account with agsXMPP, and Im online.

Then, other user with other client wants to add me .... shouldnt he only add tstUser@jabberdomain instead of tstUser@jabberdomain/Resource?

Or should I follow the approach of login twice? One with no resource, and other with any resource id? That way, any request will be received with the session without resource.
Avatar
Alex #2
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Hello jhuerta,

unlike in other IM systems you can log it with XMPP unlimited times with one account. Only the resource must be different.

So you can login at the same time with for example:

user@server.com/PocketPC
user@server.com/Office
user@server.com/Cellphone

yes you should register without the Resource. You even can't know the resource of the other contact if you are not subscribed.
The resource is only needed for the most Iq's and when you want to communicate with a specific resource. e.g. the cellphone in the example above.

Let me know if you have more questions about this, or if I did not explain it very well;-)

Alex
Avatar
jhuerta #3
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi Alex,
thanks for such a fast reply.

I have a question about "yes you should register without the Resource." Mmm how can I register without a resource if one is added by default?

What I see is that if I dont specify a resource in this code (highlighted line), then a default resource named agsXMPP will be used. Should I specify resource = blank ?

        m_XmppCon.Server = XMPPCON_SERVER;
        m_XmppCon.Username = username;
        m_XmppCon.Password = password;
        m_XmppCon.Resource = resource;
        m_XmppCon.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
        m_XmppCon.UseStartTLS = false;
        m_XmppCon.RegisterAccount = true;
        m_XmppCon.Port = XMPPCON_PORT;
        m_XmppCon.UseCompression = false;
        m_XmppCon.AutoResolveConnectServer = true;
        m_XmppCon.Open();


That part Im talking about the "default resource" is this (XmppClientConnection.cs):

                ................
        private        string                    m_Username            = "";
        private        string                    m_Password            = "";       
        private        string                    m_Resource            = "agsXMPP";       
        private        string                    m_Status            = "";
        private        int                        m_Priority            = 5;
        private        ShowType                m_Show                = ShowType.NONE;
        private        bool                    m_AutoRoster        = true;
                ................

mmmm I doing something wrong while registering a new account? This is my registering function:
 
   public bool Register(string username, string password, string resource)
    {
        m_XmppCon.Server = XMPPCON_SERVER;
        m_XmppCon.Username = username;
        m_XmppCon.Password = password;
        m_XmppCon.Resource = resource;
        m_XmppCon.SocketConnectionType = agsXMPP.net.SocketConnectionType.Direct;
        m_XmppCon.UseStartTLS = false;
        m_XmppCon.RegisterAccount = true;
        m_XmppCon.Port = XMPPCON_PORT;
        m_XmppCon.UseCompression = false;
        m_XmppCon.AutoResolveConnectServer = true;
        m_XmppCon.Open();
        // This is asynch, waiting for OnLogin to be triggered
        while (!loggedIn && !errorOccured)
        {
            System.Threading.Thread.Sleep(1000);
            // do nothing but delay
        }
        return loggedIn;
    }

thanks again,


Juan
Avatar
Alex #4
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
sorry, i sent my answer to fast.

You can register with resource. If you specify no resource (null) the server generates automatically a random resource for you.

Alex
Avatar
jhuerta #5
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
I see.

So, in that case, lets say  userA has logged in with a resource resourceA.

Then, a userB wants to subscribe to his presence, so it sends:

<presence xmlns="jabber:client" type="subscribe" to="userA@dev.jabberdomain" id="11111" />

The problem Im facing is that the userA is not getting the reply (or im not able to catch it ...) .

It would only get it if I add the resource in the request:

<presence xmlns="jabber:client" type="subscribe" to="userA@dev.jabberdomain/resourceA" id="11111" />

Summing up, the question would be:
No matter what resource and priority the user is logged in with, if a user sends a "subscribe" request to userA ... should userA be able to receive that?
Should the "subscribe: request be sent to an specific resource? to no resource at all? to the same the user is logged in at that moment?

thanks again,

Juan

Btw, about resources and priorities, this link is nice to understand and see the potential of it: http://wiki.jabber.org/index.php/Jabber_Resources
Avatar
Alex #6
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Quote by jhuerta:
Summing up, the question would be:
No matter what resource and priority the user is logged in with, if a user sends a "subscribe" request to userA ... should userA be able to receive that?
Should the "subscribe: request be sent to an specific resource? to no resource at all? to the same the user is logged in at that moment?

You always should be able to receive it. And as I said before send the subscription requests to the Bare Jid (without resource).
You subscribe to a user to get the users presence. Without subscription you get no presence, and without presence you don't know the resources of the other users. Because the resource is part of the presence packets. And you can't guess the resources of the people you want to subscribe to.

If you don't receive the subscription requests there must be another problem.

Alex
Avatar
jhuerta #7
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Thanks, now clearer.

- Juan
Avatar
jhuerta #8
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi,
I found the problem, and the solution.

Summing up for some other people.

When userA was sending this packet to userB:
            <presence to='userB@jabberDomain type='subscribe' id='AutoSubscribe'/>

userB was showing:
            <iq from='userB@jabberDomain /resourceA'
            to='userA@jabberDomain /resourceA' id='push'
            type='set'><query xmlns='jabber:iq:roster'><item subscription='to' jid='userA@jabberDomain '/></query></iq>

instead of :
            <presence from='userB@jabberDomain ' to='userA@jabberDomain /resourceA' xml:lang='en' type='subscribe' id='AutoSubscribe'/>

Therefore, I couldnt get the presence packet and accept with:
            <presence to='userB@jabberDomain '   type='subscribed' id='AutoSubscribe'/>


I read on http://forum.ag-software.de/forum.php?req=thread&posti… about sending myPresence after getting authenticated.

After adding: m_connection.SendMyPresence(); in the authentication process, i started getting presence packets.

So, after all, it seems that sending my presence was the solution.

Hope it makes sense.

- Juan
Avatar
Alex #9
Member since Feb 2003 · 4317 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes it does.

If you don't send your own presence to the server (SendMyPresence) you don't get any presence and messages from the server.

Alex
Avatar
jhuerta #10
Member since Oct 2007 · 7 posts
Group memberships: Members
Show profile · Link to this post
Hi,

I notice a similar behavior when sending the presence subscribe packet to a user that is offline.

When the user gets online, it is not getting the presence. The only reference is getting from the user who requested the subscription is in the roster:

<iq xmlns="jabber:client" from="aa1@jabberdomain/MiniClient" to="aa1@jabberdomain/MiniClient" type="result" id="agsXMPP_13"><query xmlns="jabber:iq:roster"><item jid="jjtest70@jabberdomain" subscription="none" /><item jid="uu1@jabberdomain" subscription="none" /></query></iq>

I have tried this from different clients.

Miniclient is adding the user to the ungroupped roster.

Gajim will remove automatically the contact from the roster.

Im start to think that it could something related to the jabber server (eJabberd in our case). When I tried connecting to other jabber servers (12jabber.com, borderlinenormal.com ...) I get the presence packet properly.

Is there anyway to request the presence packets that was sent when the user was offline ?
Avatar
Jabberer #11
Member since Feb 2006 · 249 posts
Group memberships: Members
Show profile · Link to this post
Quote by jhuerta:
Gajim will remove automatically the contact from the roster.
this is not a nice behavior because nothing in the XMPP RFC's forces you to use groups. There are many existing XMPP clients which have no support for grouping at all.

Quote by jhuerta:
Is there anyway to request the presence packets that was sent when the user was offline ?

No, the XMPP server has to deliver the subscription requests automatically once the user is logged in again and available.
If this does not happen then there is something wrong on your server or in your code.

  • make sure you send subscription requests to bare jids
  • make sure that you send your own presence in your client.
Software Developer
AG-Software
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 RSS