title: Sending data from flash to node.js server with socket.io
body: <p>I have a simple socket.io 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)</p>
  
  <p>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 socket.io)
  but I can't manage to do it</p>
  
  <p>this is my flash code:</p>
  
  <pre><code>Security.loadPolicyFile("http://127.0.0.1:81/crossdomain.xml");
  socket = new XMLSocket("127.0.0.1", 81);
  socket.addEventListener(Event.CONNECT, onConnect);  
  socket.addEventListener(IOErrorEvent.IO_ERROR, onError);  
  socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityEvent);
  socket.addEventListener(DataEvent.DATA, onData);
  </code></pre>
  
  <p>and the server side code is </p>
  
  <pre><code>var app = require('http').createServer(function (req, res) {...})
     , io = require('socket.io').listen(app, { log: true })
     , fs = require('fs')
  
  app.listen(81);
  
  io.sockets.on('connection', function (socket) {
      console.log("connection "+socket.id);
      socket.on("message",function(data){
          console.log("data: "+data);
      });
      socket.on("data",function(d){
           console.log('data from flash: ',d);
      });
      socket.on('disconnect', function (socket) {
          console.log("disconnect");
      });
  });
  </code></pre>
  
  <p>and my crossdomain.xml is:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt;
  &lt;cross-domain-policy&gt;
      &lt;site-control permitted-cross-domain-policies="master-only"/&gt;
      &lt;allow-access-from domain="*" to-ports="*"/&gt;
  &lt;/cross-domain-policy&gt;
  </code></pre>
  
  <p>Thank you very much for your time!</p>