读书人

使用Socket.io 在跨域时碰到的坑

发布时间: 2013-11-16 23:15:33 作者: rapoo

使用Socket.io 在跨域时遇到的坑
以下这些问题仅在跨域时才遇到

使用flashsocket,报错:
make sure the server is running and Flash socket policy file is correctly placed

解决方案,增加policyServer.js
var net = require('net');
var fs = require('fs');

// read crossdomain.xml file
var xmlFile = fs.readFileSync(__dirname +'/crossdomain.xml', 'utf8');

// this server runs on 843
var application = net.createServer(function(socket) {

socket.setEncoding('utf8');

socket.on('data', function(data) {
try{
socket.end(xmlFile, 'utf8');
}catch(e){

}
});

socket.on('end', function() {
socket.end();
});

socket.on('error', function(err) {
if (socket) {
socket.end();
socket.destroy();
}
});

}).listen(843);


crossdomain.xml

<?xml version="1.0" ?>
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>


xhr-polling不支持cluster











读书人网 >开源软件

热点推荐