Jump to content

Comet/Longpolling with concurrent AJAX calls?


Jbudone

Recommended Posts

As of now, I am so very lost! I have recently discovered this awesome technique called Comet, aka Reverse AJAX aka HTTP Push.. The idea is simple: With a "Forever iframe" you can load up a script from the server which constantly loads, and flush()'s buffered output to the client in the form of Javascript script's. These scripts may then be executed on the client WHILE the php script is still executing, hence allowing the serverside script to push events to the client as they come up. Another trick is using AJAX Longpolling, which is simply creating an AJAX request, and on the serverside if there's no events or valid data to return to the client, then it simply performs a quick sleep() and looks again for new data/events to return. As soon as it returns any data, another AJAX request is made and sent back to the server.

 

My problem is that I'm trying to send AJAX requests WHILE one of my Comet connections is alive. I've tried it both with the forever iframe, and with AJAX's longpolling. But the issue is that my AJAX requests seem to be put on a queue, and aren't sent to the serverside until AFTER the connection closes from the iframe, or until my other AJAX LongPolling request finally returns.

 

This is bad for me, because my goal is to create a Comet-based chatroom server; where the Comet side of things will continuously look for new messages in the chatroom and push it to the client, while concurrent AJAX requests can be sent to the server (eg. user types a message, leaves the channel, joins another channel, etc.)

 

I've looked all over Google, asked around on IRC, and tried all sorts of test. But I can't find a single person with the same problem as me, and I can't figure out how to get this to work or what the problem could possibly be. Is this normal behavior? Are AJAX requests not supposed to be able to send until after an iframe connection has been closed, and previous AJAX requests return first? Or maybe its because both my longpolling ajax requests call the same server script? Is there any way I can get around this? Anything anything I can do? Any tips, suggestions or enlightment in the area would be very much appreciated. Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.