pieter michels

Github    Ask me anything   

April 14, 2011 at 5:25pm

Home

Socket Policy file for AS3 with Node.js socket server

Setting up a socket server with Node.js is very simple. Consuming it with Actionscript 3 should be too.

Except, Flash has very strict policy rules concerning which domains/ips can connect through which ports on your server. So, your socket server needs to serve a crossdomain policy xml file which states that your client can connect to the server. Something like this:

I’m not using a very strict policy rule; perfect for development purpose.

When you connect with Flash to a socket server, Flash will first check if it is allowed to connect, thus requesting the xml policy file. It will send a message like this:

The problem I had was that I served the policy file only after the connection was made and the first data message (like the one above) was sent. What I didn’t do, at first, was sending the policy file right after the connection was made and also when Flash sends the request message (<policy-file-request/>).
This resulted in an error:

Ignoring policy file with incorrect syntax

So I had to change it into something like this:
(don’t forget you need to end each socket.write with ”) 

Notes

  1. pieterm posted this