 |
BOOK: Professional XMPP Programming with JavaScript and jQuery  | This is the forum to discuss the Wrox book Professional XMPP Programming with JavaScript and jQuery by Jack Moffitt; ISBN: 978-0-470-54071-8 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Professional XMPP Programming with JavaScript and jQuery section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 31st, 2010, 12:40 PM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Problems with Connection.attach
Hi,
I'm trying to get the old BOSH-Connection when I reload the page. I use the attach function and it looks like this:
Code:
connection = new Strophe.Connection( bosh_url );
var cookie = $.cookies.get( cookie_name );
if( ( cookie != null ) && ( cookie != '') ){
cookie.rid++;
connection.attach( cookie.jid, cookie.sid, cookie.rid , null );
}
In firebug I can see something like
Code:
<body rid='1645553591' xmlns='http://jabber.org/protocol/httpbind' sid='69f7bbed'/>
and
Code:
500 Could not locate connection: 1645553591
I also changed already the Openfire settings to:
Code:
xmpp.httpbind.client.idle 300
xmpp.httpbind.client.requests.polling 0.5
For cross-domain XHR I use flXHR.
Now, where is the problem? Where do I have to look for bugs?
|
|

June 1st, 2010, 04:35 AM
|
|
Authorized User
|
|
Join Date: Feb 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
SOLVED :)
I found my mistake:
I stored the cookie right after strophe connected instead of saving it right before reloading the page. Therefore the RID is obviously not the latest by reconnecting. So the following works:
Code:
$(window).unload(function() {
if( connection != null ){
set_cookie();
}else{
$.cookies.del( cookie_name );
}
});
and on page load:
Code:
connection = new Strophe.Connection( bosh_url );
var cookie = $.cookies.get( cookie_name );
if( ( cookie != null ) && ( cookie != '') && ( cookie.sid != null ) ){
connection.attach( cookie.jid, cookie.sid, cookie.rid , null );
}
Btw: Increasing the RID on attach is not necessary
|
|

June 9th, 2010, 05:41 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
Great! Glad you got it working.
|
|

June 19th, 2010, 05:24 AM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
connection.sid has value "null" in cookie
hello,
Please, dont you know why SID has value null in cookie? I use the connection.rid, connection.jid and connection.sid and I store it to cookie. Jid and rid is OK, but SID has value "null". Do you please know why?
thank you
david
|
|

June 19th, 2010, 05:54 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Hi Jack. After reading chapter 12 "Getting Attached Bootstrapping BOSH", I've decided establish session with Openfire outside of the application.
Session is established on the server side, before page loads. On page load JID, SID, RID+1 values are passed to connection.attach and session attachment works just fine up to this point.
Problems starts on page reload.
Inside $(window).unload, connection.pause() is trigered first, then JID, SID, RID values are saved in a cookie. After reload is complete, JID, SID, RID are retrieved back from a cookie, rid value is increased by 1 as var rid = Number(rid) + 1 and finally connection.attach is called.
I've double-checked rid value:
after connection.pause(), before saving to cookie = 15344200
cookie value after saving = 15344200
retrieved cookie value after page reload = 15344200
value after incrementing by 1 = 15344201
In a callback function Strophe.Status.ATTACHED is being logged to firebug console, kinda attachment is successful and strophe sends first stanza to server:
HTML Code:
<body rid='15344201' xmlns='http://jabber.org/protocol/httpbind'
sid='72ff26f6'>....whatever IQ xml goes here ....</body>
Server responded with: "404 Not Found" in ~15 seconds, Strophe.Status.DISCONNECTING and Strophe.Status.DISCONNECTED are being logged.
Openfire log: "Packets could not be found for session 72ff26f6 cannotbe delivered to client"
firebug console print screen
well, session attachment works on first page load and fails on followed reloads. Any ideas what a solution might help ?
Last edited by senpai; June 28th, 2010 at 08:11 AM..
|
|

June 19th, 2010, 06:04 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by davco81
hello, Please, dont you know why SID has value null in cookie? I use the connection.rid, connection.jid and connection.sid and I store it to cookie. Jid and rid is OK, but SID has value "null". Do you please know why?
thank you
david
|
There is definitely a mistake in your code, my guess is you forgot about connection.pause() before saving SID, try debugging the problem:
in your $(window).unload handler use call connection.pause(), then use alert() to trace SID value before and after saving to a cookie, values should be the same and defined. When page reload is complete trace it again from a cookie, value should be just the same.
Last edited by senpai; June 19th, 2010 at 06:13 AM..
|
|

June 22nd, 2010, 02:31 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by senpai
There is definitely a mistake in your code, my guess is you forgot about connection.pause() before saving SID, try debugging the problem:
in your $(window).unload handler use call connection.pause(), then use alert() to trace SID value before and after saving to a cookie, values should be the same and defined. When page reload is complete trace it again from a cookie, value should be just the same.
|
hi,
thank you for help! I think it helped even if I didnt use the pause method. Right now when I open new tab it uses the attach method, but when I open third tab, connection is aborted. Hmmm, do you think that the attach method with writint/reading RID, SID from cookie is realiable enough to use it?
thanks again
david
|
|

June 28th, 2010, 12:43 PM
|
|
Wrox Author
|
|
Join Date: Jan 2010
Posts: 178
Thanks: 0
Thanked 16 Times in 15 Posts
|
|
Quote:
Originally Posted by senpai
Server responded with: "404 Not Found" in ~15 seconds, Strophe.Status.DISCONNECTING and Strophe.Status.DISCONNECTED are being logged.
Openfire log: "Packets could not be found for session 72ff26f6 cannotbe delivered to client"
|
I assume the elapsed time between the session pausing and the next one starting was quite small?
As far as I can tell, everything looks correct with respect to the RID. I assume you double checked the SID was stored and retrieved correctly as well.
My only advice at this point is to try with Punjab as the connection manager and see if the behavior is different. It's possible there is an error in Strophe. js or in Openfire, and checking another connection manager may point us to which it is.
A 404 error could mean a small number of things. One is that the session was expired (ie, no current session matches the SID you gave). Another is that the RID you supplied is invalid for some reason, like out of the window or re-used.
It would be helpful to know the full list of RIDs used and whether any were skipped. Can you account for the primary RID through to this failing one without any gaps? Perhaps there is some condition where Strophe miscounts resulting in an eventual error.
Does it matter how much data is sent before the page reload? Or does it occur whether it happens right away or after many successful stanzas?
|
|

June 29th, 2010, 07:40 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Quote:
|
I assume the elapsed time between the session pausing and the next one starting was quite small?
|
exactly
Quote:
|
Does it matter how much data is sent before the page reload? Or does it occur whether it happens right away or after many successful stanzas?
|
I'v tried in different ways, very first attachment is always successfull, following attachments after page reload always fail. I suspect the problem hides somewhere around page unload.
Quote:
|
Can you account for the primary RID through to this failing one without any gaps?
|
I'v forced manually pause + attach from firebug console x times one after another:
PHP Code:
// without incrementing rid by 1 and this worked perfectly // however not incrementing rid after page reload immediately results in 403 Forbidden connection.pause() connection.attach(connection.jid, connection.sid, connection.rid)
// with incremented rid, resulted in 404 Not Found in ~15 seconds, // similar to attachment after page reload connection.pause() connection.attach(connection.jid, connection.sid, Number(connection.rid)+1)
Though it's not the same as pausing connection and reloading a page.
I'v also checked XEP-0124, as it says, 404 Not Found, could also mean invalid stream or key sequence, since I'm not using key sequences, when is stream considered "not valid" ?
Last edited by senpai; June 29th, 2010 at 07:50 AM..
|
|

June 29th, 2010, 07:41 AM
|
|
Authorized User
|
|
Join Date: Apr 2010
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
Here is the hole test case:
1. Very first logon:
sid from PHP session: 9eebd366
rid rom PHP session: 13806497 (already incremented by 1 in PHP)
2. attached status loged here => attachment is successfull, web client sends deliberately following requests:
HTML Code:
<body rid='13806497' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<iq type='get' xmlns='jabber:client' id='4692:sendIQ'><query xmlns='jabber:iq:privacy'/></iq>
</body>
<body rid='13806498' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<iq type='get' xmlns='jabber:client' id='4693:sendIQ'><query xmlns='jabber:iq:privacy'>
<list name='public'/></query>
</iq>
</body>
<body rid='13806499' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<iq type='get' xmlns='jabber:client' id='4694:sendIQ'>
<query xmlns='jabber:iq:roster'/>
</iq>
</body>
<body rid='13806500' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<presence xmlns='jabber:client'/>
</body>
<body rid='13806501' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<message to='[email protected]' type='chat' xmlns='jabber:client'>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>
</body>
3. reload button is clicked, before unload event is triggered and connection.pause(called)
strophe somehow sends two "chatstate" requests with the same sid :
post 1:
HTML Code:
<body rid='13806501' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<message to='[email protected]' type='chat' xmlns='jabber:client'>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>
</body>
response 1: empty (aka Aborted)
post 2:
HTML Code:
<body rid='13806501' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<message to='[email protected]' type='chat' xmlns='jabber:client'>
<active xmlns='http://jabber.org/protocol/chatstates'/>
</message>
</body>
response 2:
HTML Code:
<body xmlns="http://jabber.org/protocol/httpbind"></body>
3. unload event, connection.pause():
rid before saving to cookie: 13806502
sid before saving to cookie: 9eebd366
cookie rid after saving: 13806502
cookie sid after saving: 9eebd366
7. After page reload
cookie rid after reloading: 13806502
cookie sid after reloading: 9eebd366
cookie rid after incrementing by 1: 13806503
8. attached status loged here => attachment is kinda successfull
9. first request after session attachment
HTML Code:
<body rid='13806503' xmlns='http://jabber.org/protocol/httpbind' sid='9eebd366'>
<iq type='get' xmlns='jabber:client' id='621:sendIQ'>
<query xmlns='jabber:iq:privacy'/>
</iq>
</body>
10. response - 404 Not Found in ~15 seconds
Last edited by senpai; June 29th, 2010 at 12:25 PM..
|
|
 |