从闪存将数据发送到Node.js的服务器socket.io [英] Sending data from flash to node.js server with socket.io

查看:213
本文介绍了从闪存将数据发送到Node.js的服务器socket.io的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Node.js的一个简单的socket.io基于服务器监听套接字的端口81(例如) 我没有问题,连接和Javascript编写的客户端之间传递数据 但是很多的尝试后,我不能让我的Flash应用程序将数据连接到服务器,并传递给它 (我发现在网上的一些例子 - 但所有这些都是基于Flex的和使用的类不属于基本的AS3库部分)

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)

当我尝试使用的XMLSocket连接到插座 - 我得到一个安全沙箱冲突错误 - 我知道我需要加载的策略文件(假设使用socket.io可用) 但我不能设法做到这一点。

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

这是我的闪存code:

this is my flash 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是

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");
    });
});

和我的crossdomain.xml是:

and my crossdomain.xml is:

<?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="master-only"/>
    <allow-access-from domain="*" to-ports="*"/>
</cross-domain-policy>

非常感谢你的时间!

Thank you very much for your time!

推荐答案

对于我们的最后一个项目,我们使用 FlashSocket .IO ,工作就像一个魅力。

For our last project, we used FlashSocket.IO, worked like a charm.

我们必须做轻微adaptions在服务器端(即确保socket.io侦听端口843,而不是10843的policyfile)并激活flashsocket运输,但沟通是一件轻而易举的事。

We had to do minor adaptions on the server-side (i.e. make sure socket.io 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);
});

注:此配置要求的node.js以root身份运行

NOTE: this configuration requires node.js to be run as root!

这篇关于从闪存将数据发送到Node.js的服务器socket.io的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆