I want to write an application that uses WebSockets with node.js and socket.io in combination with Django and will be sharing data through Redis (lots of buzzwords in that sentence!).
If I run node on a different port (e.g., 5555), will I be able to connect to it with a WebSocket (or fallback method with socket.io, like long-polling, etc.) or will the same origin policy give me problems?
If so, how can I get around them?
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 in the |Sec-WebSocket-Location| field of its handshake, so that both the client and the server can verify that they agree on which host is in use.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With