本文介绍了如何使用 Flash、Socket.IO 和 NodeJS 修复这个(可能)跨域策略错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation: http://kipos.bluecodestudio.com/holdthebomb/HoldTheBombWeb.swf cannot load data from http://23.29.126.76:8000/socket.io/1/?t=1356891827452.
    at io::Socket/doHandshake()[/Users/airrider3/github/AS3-Socket.IO-XHR-Polling/xhr-polling/src/io/Socket.as:139]
    at io::Socket/connect()[/Users/airrider3/github/AS3-Socket.IO-XHR-Polling/xhr-polling/src/io/Socket.as:110]
    at io::Socket()[/Users/airrider3/github/AS3-Socket.IO-XHR-Polling/xhr-polling/src/io/Socket.as:90]
    at io::IO$/connect()[/Users/airrider3/github/AS3-Socket.IO-XHR-Polling/xhr-polling/src/io/IO.as:36]
    at MainController/endOfbluecodeSplash()[/Users/airrider3/Dropbox/Projects/Kipos/Minigames/HoldTheBombWeb/src/MainController.as:41]
    at bluecodeSplash/endOfSplash()[/Users/airrider3/Dropbox/Projects/Kipos/Minigames/HoldTheBombWeb/src/bluecodeSplash.as:55]
    at Function/http://adobe.com/AS3/2006/builtin::apply()
    at com.greensock.core::TweenCore/complete()[D:\_Flash\_AS3srccomgreensockcoreTweenCore.as:178]
    at com.greensock::TweenLite/renderTime()[D:\_Flash\_AS3srccomgreensockTweenLite.as:477]
    at com.greensock.core::SimpleTimeline/renderTime()[D:\_Flash\_AS3srccomgreensockcoreSimpleTimeline.as:93]
    at com.greensock::TweenLite$/updateAll()[D:\_Flash\_AS3srccomgreensockTweenLite.as:642]

我正在使用 Flash Builder,这是一个 ActionScript 项目,它使用 Socket.IO 模块连接到运行 NodeJS 的服务器.

I'm using Flash Builder, an ActionScript project, which connects to a server running NodeJS using the Socket.IO module.

要将 Socket.IO 与 AS3 连接,我使用了以下库 https://github.com/sbquinlan/AS3-Socket.IO-XHR-Polling它在本地测试时完美运行,来自 Flash Builder.

To connect Socket.IO with AS3 I'm using the following library https://github.com/sbquinlan/AS3-Socket.IO-XHR-Pollingwhich works perfectly while testing in local, from Flash Builder.

但是,如果托管在我的域上 [http://kipos.bluecodestudio.com/holdthebomb/],我想它会引发这个 SecurityErrorEvent 是因为我没有正确使用任何 crossdomain.xml 文件?老实说,我从来没有接触过这个话题,所以我不确定这是不是错误.

However, if hosted on my domain [http://kipos.bluecodestudio.com/holdthebomb/], I suppose it raises this SecurityErrorEvent because I am not using any crossdomain.xml files correctly? I've never gotten along with this topic, to be honest, so I'm not sure if this is the error.

无论如何,我有以下 crossdomain.xml 文件:

In any case, I have the following crossdomain.xml file:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/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>

我在我的服务器上的不同地方都有它.(它应该在托管客户端上吗?).是的,游戏托管在 bluecodestudio.com,而游戏的服务器在 IP 23.29.126.76 上,在端口 8000 上运行.

I have it in different places on my server. (Should it be on the hosting client?). Yes, the game is hosted on bluecodestudio.com, while the game's server is on the IP 23.29.126.76, running on the port 8000.

如果是跨域策略错误,有没有好心人解释一下应该采取什么措施来解决问题?

If it's the case of the crossdomain policy error, is anyone kind to explain what should be done to fix the problem?

感谢您的关注.

更新 1:

我设置了一个服务器,侦听端口 843,提供跨域文件,但我可以看到 Flash 如何不尝试加载它.(我测试了命令 python -c 'print "<policy-file-request/>%c" % 0' | nc 23.29.126.76 843 并检查了策略服务器确实是如何工作的.

I set up a server listening on port 843 giving the crossdomain file, but I can see how Flash doesn't try to load it. (I tested the command python -c 'print "<policy-file-request/>%c" % 0' | nc 23.29.126.76 843 and checked how the policy server indeed works.

SWF 为什么不尝试加载跨域策略文件?

推荐答案

哇.我刚刚在 Socket.IO 文档中读到了这个:"flash 策略端口默认为 10843

Whoa. I just read this on the Socket.IO documentation:"flash policy port defaults to 10843

默认情况下,Socket.IO 客户端将检查您服务器上的端口 10843,以查看是否允许 flashsocket 连接.Adobe Flash Player 通常使用 843 作为默认端口,但我们决定默认使用非根端口."

By default the Socket.IO client will check port 10843 on your server to see if flashsocket connections are allowed. The Adobe Flash Player normally uses 843 as default port, but we decided to default to a non root port."

这就是为什么它没有尝试从端口 843 加载文件...

So that's why it didn't try to load the file from port 843...

来源:https://github.com/LearnBoost/Socket.IO/wiki/Configuring-Socket.IO

这篇关于如何使用 Flash、Socket.IO 和 NodeJS 修复这个(可能)跨域策略错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 11:54