powered by Jive Software

XMPPBOSHConnection Fix - terminate HTTP Session

When a user got disconnected, the session would remain active, and the user would remain online.

Reading the specification for BOSH we found out we could terminate the http session on: Terminating the HTTP Session.

We have created our own XMPPBOSHConnection.as file with our patches.

Our first patch was an override over the handleStreamError() function:

Now we have modified the disconnect() function, sending an xml request to the server according to the specification, for it to terminate the session:

public override function disconnect():void
     pollTimer = null;
     requestCount = 0;
     for(var i:uint = 0; i < 10 && requestQueue.length > 0; i++) {
          var attrs:Object = {
        xmlns: "http://jabber.org/protocol/httpbind",
        rid: nextRID,
        sid: sid,
        type: "terminate"
        var subattrs:Object = {
         type: "unavailable",
         xmlns : "jabber:client"
    }     var result:XMLNode = new XMLNode(1, "body");
    result.attributes = attrs;
        var subresult:XMLNode = new XMLNode(1, "presence");
    subresult.attributes = subattrs;

We haven’t had time to check the way the requestQueue works, so just in case, we are shifting all the items from the array, and setting requestCount to 0, since the session is being terminated.


Can you attach a diff against the trunk?

Here’s the patch for the Error handling on XMPPConnection.
xmppconnectionfix.diff.zip (956 Bytes)

I’ll have to check the session fix against the trunk code, since we were using the beta.

XMPPBOSHConnection was fixed on the trunk version from SVN, so that fix is not necessary.

Please use the SVN trunk version, it has many improvements over the old beta release.

We started using the trunk version. We are now trying to migrate our application to the new features. We’ll try to keep it updated, and keep on posting patches and fixes.


Hi, I just updated to the trunk version too. Much much better, everything seems to be working after just a little struggle. Although, after closing my application, the user remains connected for at least another minute. Any break-through on this guys? The patches around this forum, as mentioned above, were applied already to the trunk version, so I can’t understand why users remain logged in!?!

If the application is in a browser window and the closing it refers to the action of closing the browser window, the flash in it does not know wether it should do something.

Simply using “onunload” event to call something via Externalinterface might do the trick.

Any solution which could achieve the same in a simpler way is welcome.

That makes sense… thanks for the quick reply! I’ll publish the code here once I get to it.

I have the same problem. When a user is closing his window or exiting the website by changing the URL of his browser, he remains online for a certain amount of time before being indeed disconnected.

It is not just something about http polling ? Or a timer that checks if the user is online or not, well I don’t know how BOSH is functionning but there must be something like this to “emulate” the connection like the socket connection ?

I’ll check to see if I can find a fix other than the “unload JS” method… which may work but I’m not really confident because there would not be enough time for calling an AS3 method with a JS method called by the unload event and then to send the correct XMPP message before the window being closed…

(Sorry for my poor English ! )

And it seems I have the same “delay” problem about user presence in chatrooms.

That’s quite funny because when a friend is setting its presence as offline for example (“xa”), my application receives the notification immediatly (with Roster.as) but it seems I have to wait a few seconds to that the Room object receives or notifies me… Strange…

Your English is great, Geomaster.

I am trying to resolve the proxying on my Apache. It is going to take me another couple of days. After that, I will look into this problem as I MUST resolve this issue. My users will be going in and out from the chatroom quite often and their presence must be set instantly. I will definitely post any new findings. Thanks for writing back, many people don’t take the time!

Thanks gianluca

I don’t know exactly what your problem is with Apache but I had one myself concerning my Flash application which wasn’t able to find any crossdomain.xml file at the http-bind URL of my server.

For the other issue, I have to find a solution too because my application needs to instantly receive users presence.

For now, I’m still searching for a solution and looking into the code to find why it works for roster items presence and not for chatrooms.

For now, I can’t find any answers

I will try to install locally a newer version of eJabber because we are using a very old one and I think these latency problems are coming directly from the server. Stay tuned !

We tried something like this with BOSH connection a while back, using JS onunload event. The behavior varied across browsers, where some would let you send off the last request, but others wouldn’t. There were also variations in behavior when you closed just a tab vs. closing the entire browser.

IIRC, BOSH connections do have a timeout period (I think it’s the “inactivity” field but have to check the spec) after which they will automatically terminate the session. If you want instant disconnect and you’re using Flash, a direct socket connection is best for this kind of behavior. I don’t know if that’s possible in your environment.


The fact is we are using socket connections for two years now and it works great

But one of our clients is behind a proxy and won’t do anything to “unsecure” his its network. So we’re updating our API so that if we detect that sockets cannot be used, we’re going through BOSH.