How to serve policy file from Socket.IO/Node.js

1.6k views Asked by At

I've created a Socket.IO server which pushes listing details to connected clients. Over HTTP in a browser, everything works as intended using web sockets, however one of the client types that will consume the service is strictly Flash (not socket fallback, just straight up Flash). We are using the AS3 Web Socket Client library.

When the Flash client (built by another team) tries to connect to the server, it's getting a security sandbox violation. I'm aware this has to do with the policy file serving from the Socket.IO server, but I'm at a loss as to exactly how to serve up this file. When I telnet 127.0.0.1 10843 or telnet 127.0.0.1 843 I get no response. If I recall, in past projects we've been able telnet to the policy file server to get the response. This would be ideal to help me verify that it's being served.

I understand that the default port is 10843, and have also tried setting to 843.

Here's what I have:

  • Push service running on localhost:3000
  • Browser clients can connect and join channels no problem
  • I have a crossdomain.xml file in root directory (not sure if this is needed or not)

I have the following settings pertaining to the policy file:

// Socket Setup
io.set('transports', ['websocket','flashsocket']);
io.set('flashPolicyServer', true);
io.set('flash policy port', 843);

An aside (maybe), with these settings I'm also getting an error on starting the service (though it still starts):

Option flashPolicyServer is not valid. Please refer to the README. 
Option flash policy port is not valid. Please refer to the README.

I'm at a loss. Hopefully not a duplicate; I searched high and low and believe I'm missing something minor. Any recommendations?

2

There are 2 answers

6
enolam On

According to the socket.io documentation, the flash policy server defaults to true when the flashsocket transport is enabled. This means that the flashPolicyServer (which should be flash policy server) option is unnecessary. Try setting the port before setting the transports as well... like this.

io.set('flash policy port', 843);
io.set('transports', [ 'websocket', 'flashsocket' ])

This ensures that when the flash socket server starts up, it starts with that port, rather than starting, getting killed and then restarted with the new port. Also, since 843 is a root port, make sure it has permission to use that port.

edit It seems as though socket.io dropped support for flash outright. The docs on their github are for 0.9.0. Which is confusing. There is an alternative that might be useful although I have not tried it. FlashSocket.io should help facilitate your needs.

4
Oleg On

It seems that Socket.IO developers decided to get rid of some transports, and thus since 1.0 there is no Flash transport support. This is a bit confusing because on the new docs there is simply no mentioning of Flash transport presence at all.

In Socket.IO 0.9 you could find WebSocketMain.swf and WebSocketMainInsecure.swf files somewhere inside socket.io folder. In 1.* there are no any files with .swf extension.

So if you need Flash support you should install Socket.IO 0.9 with this command:

npm install [email protected]