I have a client which is in flash as3. I got 2 server, one main for the flash client and a socket policy server.
I run the socket policy server on port 843 and my client on any port X for example.
Now when i connect with my flash client, using this:
Security.loadPolicyFile("xmlsocket://domain.com:port");
SecureSocket.connect(ip, port);
It actually connect first to my policy socket server, send a policy-file-request line and receive the one i am sending using my server which look like this:
tls.createServer(options, function(sock) {
sock.on('data', function(data) {
console.log('Data receveid: '.cyan + data + ' from ' + sock.remoteAddress);
if (data == "<policy-file-request/>\0") {
sock.write('<?xml version="1.0"?><!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"><cross-domain-policy><site-control permitted-cross-domain-policies="all"/><allow-access-from domain="*"></cross-domain-policy
console.log('Sent policy file to: '.green + sock.remoteAddress);
}
...
After that, the connection is closed automatically. Then it try to connect to my real server and send to server the policy-file-request line again then connection close. I really dont know what to do from now on ive been trying all days and searching around the web. Anyone got an idea of what i am missing?
Ok I finally got it to work. First I wanted a SSL connection from my client to my game.
So I need a policy socket server to work on that port and found some on adobe website wrote in python and perl. Forget them, they won't work in this case.
Because I am trying to access server in SSL so I need also a SSL policy server.
Since there is none on the net I wrote a simple one:
I went crazy in the allow access domain form because i had some security sandbox violation with a reduced one, so ive put it all. I will clean this later.
As you can see, I had to add a
\0
at end of sending the policy or Flash wouldn't accept it.Two day wasted on this. And I still don't understand why Adobe would make the connection so hard between flash and the world. Never saw this kind of policy elsewhere while programming sockets.