Sarah
Sarah

Reputation: 513

Ajax calls queued while connected to Flash Socket

I'm running into a problem while running both a Flash socket and using Ajax to load pages. Both work fine separately. I am able to browse my site using the Ajax calls, or I am able to send/receive messages through the socket.

However, when the socket is connected for some reason the Ajax calls start to seemingly be put into a queue and never actually finish until I stop the socket. If I disconnect from the socket, or close the socket on the server side, then the Ajax call immediately finishes and loads the page. The Ajax call never times out, it just waits forever, right up until I close the socket connection.

In JavaScript, I'm using jQuery's $.getJSON() function to load the pages (which I thought were asynchronous calls).

In Flash I'm using the basic ActionScript 3 Socket class:

this._socket = new Socket();
this._socket.addEventListener(Event.CONNECT, onConnectHandler);
this._socket.addEventListener(Event.CLOSE, onCloseHandler);
this._socket.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
this._socket.addEventListener(ProgressEvent.SOCKET_DATA, onDataHandler);
this._socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityErrorHandler);

EDIT:

I've verified that no HTTP request is being made. It is in fact being queued by the browser for some reason. I also noticed that not only will it queue the Ajax requests, but it also will queue a browser refresh. If I hit the refresh button it hangs forever as well.

EDIT 2:

Actually, I was checking port 80 when I should have been checking port 443. There is actually a request being made to the server, it's just hanging for some reason. This leads me to believe that there's an issue with the socket (which is using PHP) somehow making the PHP processor queue the requests, or maybe Apache is queuing the requests since it sees PHP is being used by the socket. I'm still not sure why the additional requests to the PHP processor are not being fulfilled until the socket is closed, but I'm pretty sure it has something to do with the fact that the PHP socket is in an always-open state and blocking the other requests.

Upvotes: 2

Views: 232

Answers (1)

Sarah
Sarah

Reputation: 513

Apparently the issue is due to the 2-limit connection that browsers implement. Since the socket uses one of the persistent connections to the host, the rest of the HTTP requests get bottle-necked.

The problem and solution are described here:

...if the browser was going to limit the number of connections to a single host that the answer was simply to trick the browser into thinking it was talking to more than one host. Turns out doing this is rather trivial: simply add multiple CNAMEs for the same host to DNS, and then reference those as the host for some of the objects in the page.

Upvotes: 0

Related Questions