BOSH session

513 views
Skip to first unread message

Jojje

unread,
Nov 26, 2009, 6:48:02 PM11/26/09
to Strophe
Hi all!

I just started experimenting with xmpp, bosh and strophe. I got an
openfire server setup on ubuntu and i´ve built a community site.

I got a newbie question, and im not sure i use the correct terms here
so bare with me.

When users log in they also login on the openfire bosh server with
strophe. How do i keep the connection alive between pages. i use ajax
for a few pages but the rest reloads. Do i have to reconnect on every
page?

Thanks in advance

George

Jack Moffitt

unread,
Nov 26, 2009, 7:36:43 PM11/26/09
to str...@googlegroups.com
> When users log in they also login on the openfire bosh server with
> strophe. How do i keep the connection alive between pages. i use ajax
> for a few pages but the rest reloads. Do i have to reconnect on every
> page?

You can use Strophe's attach() function to resume a connection on the
next page, but you'll have to store the SID, RID, and JID of the
connection somewhere (in a cookie, etc). Also, if the user opens a
new tab, you'll then have two pages open at once, and the connection
can't be shared.

Alternatively, each page could make its own connection, but you will
then need to figure out a good way to share application state.

jack.

Jojje

unread,
Nov 26, 2009, 7:46:27 PM11/26/09
to Strophe
Thanks for the quick answer :)

I´ll try the attach() function :)

Ok so that is a problem when two pages are open at the same time, is
there a way to prevent this? The thing is that ive built a chat for
the site, and its open on every page, much like facebooks chat.

Thanks

George

Jojje

unread,
Nov 26, 2009, 8:31:24 PM11/26/09
to Strophe
Oh and is there an easy way to extract the RID and SID?

George

Jack Moffitt

unread,
Nov 26, 2009, 9:50:22 PM11/26/09
to str...@googlegroups.com
> Oh and is there an easy way to extract the RID and SID?

conn.rid and conn.sid should do it.

jack.

Jojje

unread,
Nov 27, 2009, 12:37:57 AM11/27/09
to Strophe
ok that worked well :) Thanks...

I´m sorry to bother you with one more question.
I get a 404 invalid SID back when i go to a new page. I managed to put
the sid rid and jid in a cookie, and i put a $(document).ready event
handler where i put a connection.attach() wich i pass the jid, sid and
rid from the cookie, but i still get the error. Any thoughts on what i
´m doing wrong here?

regards

George

Markus Lux

unread,
Dec 10, 2009, 6:19:39 AM12/10/09
to Strophe
I got the same problem here. Did you solve this problem?

Markus.

Jack Moffitt

unread,
Dec 13, 2009, 4:28:07 PM12/13/09
to str...@googlegroups.com
> I get a 404 invalid SID back when i go to a new page. I managed to put
> the sid rid and jid in a cookie, and i put a $(document).ready event
> handler where i put a connection.attach() wich i pass the jid, sid and
> rid from the cookie, but i still get the error. Any thoughts on what i
> ´m doing wrong here?

My guess is that you need to bump the rid by one. You'll also want to
check that the session didn't expire. How long was it between the
previous request and the current one that 404s?

jack.

Myers Carpenter

unread,
Dec 14, 2009, 5:18:10 PM12/14/09
to str...@googlegroups.com


On Sun, Dec 13, 2009 at 4:28 PM, Jack Moffitt <meta...@gmail.com> wrote:
My guess is that you need to bump the rid by one.  You'll also want to
check that the session didn't expire. How long was it between the
previous request and the current one that 404s?


With a BOSH window at 5, shouldn't this work anyway?

myers

Myers Carpenter

unread,
Dec 14, 2009, 5:18:39 PM12/14/09
to str...@googlegroups.com
On Sun, Dec 13, 2009 at 4:28 PM, Jack Moffitt <meta...@gmail.com> wrote:
My guess is that you need to bump the rid by one.  You'll also want to
check that the session didn't expire. How long was it between the
previous request and the current one that 404s?

Jack Moffitt

unread,
Dec 14, 2009, 5:32:35 PM12/14/09
to str...@googlegroups.com
>> My guess is that you need to bump the rid by one.  You'll also want to
>> check that the session didn't expire. How long was it between the
>> previous request and the current one that 404s?
>>
>
> With a BOSH window at 5, shouldn't this work anyway?

Depends on the implementation. ejabberd used to be quite strict on ordering.

Also, in javascript it's very easy to do:

rid + 1 when you mean parseInt(rid) + 1

If rid is a string, that will make your new rid off by a factor of 10.
I just ran into this myself trying to do an http-pre-bind example for
strophe.

jack.

Markus Lux

unread,
Jan 9, 2010, 7:43:55 AM1/9/10
to Strophe
Until yesterday I've been struggling with Openfire and attaching to
existing jabber sessions.
I got it working. Partially. I was able to attach to externally
created sessions and could attach to already attached sessions by
incrementing the rid as mentioned before. That worked for me as long
as I didn't reload the page. Somehow my session would be immediately
destroyed by Openfire when I did that. I tried incrementing the rid by
x, decrementing it, leaving it as it is, but nevertheless reloading
and reattaching did not work for me.

So I gave up using Openfire and installed ejabberd and now it really
works like a charm. I don't even need to modify the rid or do any
other workarounds. You also need to set up a ProxyPass directive in
your httpd config as this was done with Openfire, too.

So I guess Openfire is a bit buggy in this case or at least too strict
in managing http-bind/BOSH connections.

-Markus

Raj

unread,
Jan 15, 2010, 6:58:13 PM1/15/10
to Strophe
How do I get access to RID? I know of connection.rid. rid is something
which is changing based on the timers as I understand. Is there a way
I can listen to rid change (increment in rid value) so that I can
store it in cookie and use it between pages?
-Raj

Jack Moffitt

unread,
Jan 15, 2010, 7:00:55 PM1/15/10
to str...@googlegroups.com
> How do I get access to RID? I know of connection.rid. rid is something
> which is changing based on the timers as I understand. Is there a way
> I can listen to rid change (increment in rid value) so that I can
> store it in cookie and use it between pages?

In onbeforeunload or onunload, just call pause, and grab
connection.rid and stash it. Then use it when you call attach. It
will keep changing on every request, so you'll want to read it after
you've stopped requests with pause().

jack.

Raj

unread,
Jan 15, 2010, 7:07:04 PM1/15/10
to str...@googlegroups.com
Are onbeforeunload or onunload functions in strophe? I don't see them in my version which is the latest that I have downloaded.
 -Raj

--
You received this message because you are subscribed to the Google Groups "Strophe" group.
To post to this group, send email to str...@googlegroups.com.
To unsubscribe from this group, send email to strophe+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/strophe?hl=en.




Jack Moffitt

unread,
Jan 15, 2010, 7:15:35 PM1/15/10
to str...@googlegroups.com
> Are onbeforeunload or onunload functions in strophe? I don't see them in my
> version which is the latest that I have downloaded.

Those are browser events that fire on page unload.

jack.

Reply all
Reply to author
Forward
0 new messages