Sending data from flash to node.js server with

I have a simple based server in node.js that listens to a socket in port 81 (for example)
I have no problem connecting and passing data between clients written in Javascript
But after a lot of tries I can’t get my Flash app to connect to the server and pass data to it
(I found some examples in the web – but all of them are flex based and use classes that aren’t parts of the basic AS3 libraries)

when I’m trying to connect to the socket using a XMLSocket – I get Security Sandbox Violation Error – I know that I need to load the policy file (which suppose to be available using
but I can’t manage to do it

this is my flash code:

socket = new XMLSocket("", 81);
socket.addEventListener(Event.CONNECT, onConnect);  
socket.addEventListener(IOErrorEvent.IO_ERROR, onError);  
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityEvent);
socket.addEventListener(DataEvent.DATA, onData);

and the server side code is

var app = require('http').createServer(function (req, res) {...})
   , io = require('').listen(app, { log: true })
   , fs = require('fs')


io.sockets.on('connection', function (socket) {
    console.log("connection ";
        console.log("data: "+data);
         console.log('data from flash: ',d);
    socket.on('disconnect', function (socket) {

and my crossdomain.xml is:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "">
    <site-control permitted-cross-domain-policies="master-only"/>
    <allow-access-from domain="*" to-ports="*"/>

Thank you very much for your time!

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

For our last project, we used FlashSocket.IO, worked like a charm.

We had to do minor adaptions on the server-side (i.e. make sure listens for the policyfile on port 843 rather than 10843) and activate the flashsocket transport, but the communication was a breeze.

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

NOTE: this configuration requires node.js to be run as root!

Solution 2

Try this solution (you need to setup the socket policy server in addition to the game server on the port 843)

BTW: when you use socket always use url like xmlsocket://host:port (for port 843 flash loads policy file automatically) rather than http://host:port witch is only for http requests.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply