How to server flash policy file with socket-io 1.3.5 (node server)?

792 views Asked by At

I'm trying to serve inline flash policy file on port 3000, but with no luck.

I can not catch any callback from flash policy call (<policy-file-request/>\0). And I don't know how to serve send policy file back to flash through the socket.

Somethig like this: Setting up a socket policy file server from Adobe

This is code from server:

var server   = require('http').createServer();
var io       = require('socket.io')(server);

var port = 3000;

var xml = '<?xml version="1.0"?>\n<!DOCTYPE cross-domain-policy SYSTEM \n"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">\n<cross-domain-policy>\n';
    xml += '<site-control permitted-cross-domain-policies="master-only"/>\n';
    xml += '<allow-access-from domain="*" to-ports="*"/>\n';
    xml += '</cross-domain-policy>\n';

io.on('connection', function (socket) {
    socket.on('<policy-file-request/>\0', function (data, callback) {
        console.log('socket policy-file-request 0');
        callback(xml);
    });
});

server.listen(port, function () {
    info('Server listening at ' + port);
});

And from client:

Security.loadPolicyFile("xmlsocket://example.com:3000");
2

There are 2 answers

2
Blubberguy22 On

You are doing the socket.io connections and communications incorrectly. You have to emit to the sockets instead of using a callback method, as such (a modification of your code):

Server:

var server   = require('http').createServer();
var io       = require('socket.io')(server);

var port = 3000;

var xml = '<?xml version="1.0"?>\n<!DOCTYPE cross-domain-policy SYSTEM \n"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">\n<cross-domain-policy>\n';
    xml += '<site-control permitted-cross-domain-policies="master-only"/>\n';
    xml += '<allow-access-from domain="*" to-ports="*"/>\n';
    xml += '</cross-domain-policy>\n';

io.on('connection', function (socket) {
    socket.on('<policy-file-request/>\0', function (data) {
        console.log('socket policy-file-request 0');
        socket.emit('<policy-file-request/>\0', xml);
    });

    socket.on('<policy-file-request/>', function (data) {
        console.log('socket policy-file-request');
        socket.emit('<policy-file-request/>', xml);
    });
});

server.listen(port, function () {
    info('Server listening at ' + port);
});

Client:

//
//Existing code (socket setup)
//

socket.on('<policy-file-request/>\0', function(data){
    Security.loadPolicyFile(data);
});
socket.on('<policy-file-request/>', function(data){
    Security.loadPolicyFile(data);
});
1
akmozo On

What about trying the npm crossdomain package which I recommended as a solution ( take look on the comments ) in this question ?

Hope that can help.