first of all, I did try searching but... deh, couldn't find anything related. If it's a well known issue, call me a noobie, but please set me on the right path :) and thanks.
I'm beginning to bang my head on Ajax and Comet, bought WROX "Professional Ajax 2nd ed" book and started rigging my own chat. So I made some experiments with ajax first, then dropped some comet in, and lo and behold I have a measly chat-page. Lovely. Now onto my problem.
My chat page receives messages just fine, and sends messages just fine as long as I'm doing one or the other thing. Not both.
My analysis (and firebug, god bless firebug) shows that while the comet connection is open, the ajax request stays waiting. As soon as I stop the comet, the ajax post gets served and obtains correct results. I can restart comet then and it'll serve the message I just inserted. I know there's a 2 connection limit (raised to 6 in FF3, apparently), I should hit it but not go beyond it.
- client.php is the client - has an iframe src=about
:blank that I redirect to the server script (actions/chat.php). Normally the comet frame would be reset every minute, but I've commented that part to reduce complexity.
- actions/chat.php is the server script. Does both accepting new messages and sending out received ones.
- I tried moving the post message action to another script, action/chatmsg.php - same behavior.
- I'm sure the comet frame is alive when I send the message: I can see the heartbeats coming and firebug reports it's loading. The POST with the new message OTOH is stuck, no readyState notification. As soon as I stop the comet, without further action I receive the notifications and the correct answer from server about the msgs I sent before.
- I tried connecting to the chat from two different clients (IE and FF) and both have it working fine - well "as expected", I receive messages and heartbeats but can't post.
- I don't have any other connection, ajax request or anything else going on while I'm doing this.
- According to research, FF3 should be able to handle 6 concurrent connections to the same domain. I'm unable to reach 2 :(
- I'm using PHP/mySQL + Ajax/Comet.
- Aside from zXML setting a property that only has a getter, there's no error in the code. PHP doesn't report issues either.
Can anyone enlighten me? I'm seriously confused.
The test page is at http://overlord-test.99k.org/client.php
- feel free to go play with it. If you happen on the index just hit "ajax it" to be redirected.
The "[beat]" you'll see are comet heartbeating. The [XHR:#] are onReadyStateChange notification statuses (XHR.readyState).
Works on firefox and IE8 for now, haven't checked any other browser.