Can WebSockets (or AJAX long-polling, etc.) run on a different port than the original HTTP request? Can WebSockets (or AJAX long-polling, etc.) run on a different port than the original HTTP request? ajax ajax

Can WebSockets (or AJAX long-polling, etc.) run on a different port than the original HTTP request?


Socket.io supports JSONP polling which is commonly used for cross-domain long polling (apart from CORS which is not supported by every browser). On cross-domain subject regarding WebSockets - specification states the following:

The server includes the hostname inthe |Sec-WebSocket-Location| fieldof its handshake, so that both theclient and the server can verifythat they agree on which host is inuse.

You "should" be able to use WebSockets with different port, in fact you probably have no other choice since standard ports like 80 will be used by other web server to serve your Django based application. There will be also potential problems with browser specific parallel connection limits if you use the same domain and port (for example you can see this in Facebook chat when you try to open more than one tab within the same browser context - each tab is connected to different subdomain during long polling to overcome these limits).


The answer is "sometimes". Its very much browser and security policy specific.

Assuming you're using Socket.IO... I've had no issues, except in Opera where it was unable to bypass the SOP (Same-origin policy) rules. The fix was enabling WebSockets.


socket.io does support cross-domain connections (see FAQ). A different port will work fine.