问题描述
限时送ChatGPT账号..我一直在使用 gimite/web-socket-js 来实现 WebSocket过去只是 Chrome 和 Safari 的开发版本.我想从 Ruby 服务器转移到 Node.js.突然它在 Chrome 之外的任何东西都不起作用.
I've been using gimite / web-socket-js to implement a WebSocket past simply Chrome and development builds of Safari. I want to move away from the Ruby server and onto Node.js. Suddenly it doesn't work in anything but Chrome.
我怀疑这与 Flash Socket Policy 文件有关我需要实施.我想将其实现为外部 Node.js 进程,以免与原始应用程序混淆.我正在使用 node-websocket-server 用 Node.js 实现 WebSocket 协议,并且同样,我也希望 不要 搞砸.
I suspect that this has to do with the Flash Socket Policy file that I need to implement. I would like to implement this as an external Node.js process so as not to muddy with the original application. I am using the node-websocket-server for implementing WebSocket protocol with Node.js, and again I would prefer to not mess with that either.
似乎最简单的方法就是运行 flashsocket.js,但运行它给了我以下错误:
It seemed like the simplest thing to do would be to run flashsocket.js, but running that gives me the following error:
sys:334
ctor.prototype = Object.create(superCtor.prototype, {
^
TypeError: Object prototype may only be an Object or null
at Function.create (native)
at Object.inherits (sys:334:29)
at Object.<anonymous> (/Users/me/Projects/testing/websocket/node-websocket-server/flashsocket.js:10:16)
at Module._compile (node.js:472:23)
at Module._loadScriptSync (node.js:479:10)
at Module.loadSync (node.js:349:12)
at Object.runMain (node.js:532:24)
at node.js:762:10
这里我们遇到了 Node.js 喜欢的可爱的神秘错误.
Here we run into the lovely cryptic errors Node.js is loved for.
我的问题是是否有一个独立的全局闪存套接字策略服务器,我可以运行 Node.js 或其他应用程序?我的理解是我只需要让它驻留在端口 843 上.或者是否有另一个用于 Node.js 的 WebSocket 库可以像 Ruby 服务器那样处理 Flash 策略?
My question is is there a stand alone global flash socket policy server I can run off of either Node.js or another application? My understanding is that I only need to have it reside on port 843. Or is there another WebSocket library for Node.js that will handle the Flash Policy like the Ruby server does?
推荐答案
在 Node.js 邮件列表的帮助下,我想出了以下内容:
With a bit of help from the Node.js mailing list I came up with the following:
var net = require("net"),
domains = ["localhost:8081"];
net.createServer(
function(socket)
{
socket.write("<?xml version=\"1.0\"?>\n");
socket.write("<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia/xml/dtds/cross-domain-policy.dtd\">\n");
socket.write("<cross-domain-policy>\n");
domains.forEach(
function(domain)
{
var parts = domain.split(':');
socket.write("<allow-access-from domain=\""+parts[0]+"\"to-ports=\""+(parts[1]||'80')+"\"/>\n");
}
);
socket.write("</cross-domain-policy>\n");
socket.end();
}
).listen(843);
我还为 WebSockets 应用程序编写了(简要)教程使用 Flash 套接字.
这篇关于在 Node.js 中使用 Flash 套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论