node.js + Socket.IO: Cannot Connect to Web Socket Server (SecurityError)

What to do with errors like [WebSocket] cannot connect to Web Socket server at ws://123.456.789.123:8080/socket.io/flashsocket (SecurityError).

If you're getting errors like this:

[WebSocket] cannot connect to Web Socket server at ws://123.456.789.123:8080/socket.io/flashsocket (SecurityError)

when trying to connect to your node.jsserver using Socket.IO from browsers without built-in WebSocket, this is because your server does not have enough rights to listen on port 843 (which is default port for obtaining Flash security police file - mandatory from Flash Player version 9,0,115,0).

To see which ports are open and listening, execute this in your shell:

netstat -an | grep "LISTEN "

You should see two lines like these:

tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:843             0.0.0.0:*               LISTEN

If you see only first one, with port 8080, it means that your server does not listed on port 843, and FlashSocket transport will not work.

There are few solutions - you can open port 843, you can lower FlashSocket transport priority using IO.Socket Transports option, or you could just give your server enough rights to listen on this port by running it using sudo:

sudo node your_server.js

And voila, FlashSocket transport works again!