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!

1/16/2013 10:38:45 PM

Accepted Answer

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!

1/17/2013 9:49:30 AM

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow