简体   繁体   English

在Wamp上将PHP套接字服务器用于AS3:违反沙箱

[英]Using a PHP Socket Server for AS3 on Wamp: Sandbox Violation

I know this has been touched on a lot, however, despite it all, I just don't get it. 我知道这个问题已经涉及很多,但是尽管如此,我还是不明白。 If you guys could bear with me :( 如果你们可以忍受我:(

So, I've got this Code: 因此,我有以下代码:

import flash.net.*;
import fl.controls.*;
import flash.events.MouseEvent;
import flash.events.DataEvent;
import flash.events.SecurityErrorEvent;

var mySocket = new XMLSocket();
trace(Security.sandboxType)
pushMsg.addEventListener(MouseEvent.CLICK, realsedButton);
//mySocket.connect("192.124.5.2",9999);
mySocket.addEventListener(Event.CONNECT, xmlsocket);
mySocket.addEventListener(Event.CLOSE, xmlsocket);
mySocket.addEventListener(IOErrorEvent.IO_ERROR, xmlsocket);
mySocket.addEventListener(DataEvent.DATA, dataHandler);
mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityHandler);   

msgArea.htmlText = "Started!";
connectToServer();
function connectToServer()
{
    msgArea.htmlText += "Inside connect To Server";
    mySocket.connect("localhost",9999);
}

function securityHandler(evt: SecurityErrorEvent)
{
    msgArea.htmlText += "SecurityError";
}

function dataHandler(evt:DataEvent)
{
    trace("Inside dataHandler")
    var xml = XML(evt.target.data);
    msgArea.htmlText += xml;
}


function xmlsocket(Event)
{
    msgArea.htmlText += "inside xmlSocket";
    switch(Event.type)
    {
        case 'ioError':
            msgArea.htmlText += "Inside dataHandler";
            msgArea.htmlText += "<b>Server connection failed!</b>";
            break;

        case 'connect':
            msgArea.htmlText +="Inside Connect";
            msgArea.htmlText += "<b>Server connection establed!</b>";
            break;

        case 'close':
            msgArea.htmlText +="Inside Close";
            msgArea.htmlText += "<b>Server connection lost</b>";
            break;
    }
}
function msgGO() 
{
    msgArea.htmlText +="Inside msgGO";
    if (inputMsg.htmlText != "") 
    {
        msgArea.htmlText +="Inside msgGo2";
        mySocket.send(inputMsg.htmlText+"\n");
        inputMsg.htmlText = "";
    }
}

function realsedButton(evt:MouseEvent)
{
    msgArea.htmlText +="Inside ReleasedButton";
    msgGO();
}

I've done a LOT of testing, I'll try and sum it all up neatly. 我已经做了很多测试,我会尽力总结一下。

If run from Flash directly (ctrl+enter) and the socket server is OFFLINE and the permissions is set to Network AND the line mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityHandler) is COMMENTED OUT 如果直接从Flash运行 (ctrl + enter),并且套接字服务器为OFFLINE ,并且权限设置为Network ,则行mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityHandler)为COMMENTED OUT

The output is as Followed: 输出如下:

  • Started! 开始了!
  • Inside Connect to Server 内部连接到服务器
  • Inside xmlsocket 内部xmlsocket
  • Inside dataHandler 内部dataHandler
  • Server Connection Failed 服务器连接失败

Error #2044 unhandled security error.txt = error #2048 security sandbox violation file ///G|/flash%20Stuff/socketClientNetwork.swf cannot load data from localhost:9999 at socketClientNetwork_fla::maintimeline/frame 1{} 错误#2044未处理的安全error.txt =错误#2048安全沙箱违规文件////G|/flash%20Stuff/socketClientNetwork.swf无法在SocketClientNetwork_fla :: maintimeline / frame 1 {}上从localhost:9999加载数据

If run from the SWF and the socket server is OFFLINE and the permission is set to Network AND the line (from above) is NOT commented out The output is as follows: 如果从SWF运行并且套接字服务器为OFFLINE ,并且权限设置为Network并且该行(从上面)未注释掉,则输出如下:

  • Started! 开始了!

    Inside Connect to Server 内部连接到服务器

    Security Error 安全错误

If run from Flash directly (ctrl+enter) and the socket server is OFFLINE and the permissions is set to Local AND the line mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityHandler) is COMMENTED OUT 如果直接Flash运行(ctrl + enter),并且套接字服务器为OFFLINE ,并且权限设置为Local ,则行mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityHandler)为COMMENTED OUT

The output is as follows: 输出如下:

  • Started! 开始了!
  • Inside Conenct to Server 内部连接到服务器
  • Inside xmlsocket 内部xmlsocket
  • Inside datahandeler 内部数据处理程序
  • Server Connection Failed 服务器连接失败

Error #2044 unhandled security error.txt = error #2048 security sandbox violation file ///G|/flash%20Stuff/socketClientLocal.swf cannot load data from localhost:9999 at socketClientLocal_fla::maintimeline/frame 1{} 错误#2044未处理的安全error.txt =错误#2048安全沙箱违规文件////G|/flash%20Stuff/socketClientLocal.swf无法在SocketClientLocal_fla :: maintimeline / frame 1 {}上从localhost:9999加载数据

If run from the SWF and the socket server and the socket server is OFFLINE and the permissions is set to Local AND the line (as above) is NOT commented 如果从SWF和套接字服务器运行,并且套接字服务器为OFFLINE ,并且权限设置为Local并且未注释该行(如上)

  • Started! 开始了!
  • Inside Connect to Server 内部连接到服务器
  • Security Error 安全错误

SWF :: Online :: Local :: Commented SWF ::在线::本地::评论

  • Started! 开始了!
  • Inside Connect to Server 内部连接到服务器
  • Security Error 安全错误

FLA :: Online :: Local :: Uncommented FLA ::在线::本地::未注释

  • Started! 开始了!
  • Inside Connect to Server 内部连接到服务器
  • Inside xmlsocket 内部xmlsocket
  • Inside connect to Server 内部连接到服务器
  • Connection Established 连接已建立

SWF::Online::Network::Commented SWF ::在线::网络::评论

  • Started! 开始了!
  • Inside Connect to Server 内部连接到服务器
  • Security Error 安全错误

FLA::Online::Network::Uncommented FLA ::在线::网络::未注释

  • Started! 开始了!
  • Inside connect to server 内部连接到服务器
  • Inside xml socket 内部xml套接字
  • Inside connect 内部连接
  • Server Connection Established 服务器连接已建立

You'll have to move the swf on filesystem to your local web server's document root folder or a subfolder of it and then type in browser address bar: 您必须将文件系统上的swf移动到本地Web服务器的文档根文件夹或其子文件夹,然后在浏览器地址栏中输入:

http://localhost/socketClientLocal.swf

instead of 代替

file:///G|/flash%20Stuff/socketClientLocal.swf

Additionally you'll have to create a so called 'socket policy file' named crossdomain.xml : 此外,您还必须创建一个名为crossdomain.xml所谓的“套接字策略文件”:

<?xml version="1.0"?>
<cross-domain-policy>
    <allow-access-from domain="localhost" toports="*"/>
</cross-domain-policy>

On connect() Flash Player first tries to load this file. connect() Flash Player首先尝试加载此文件。 If it fails to load or the settings restrict access, flash player triggers the security error you encountered too. 如果加载失败或设置限制访问,则Flash Player也会触发您遇到的安全错误。

Flash Player tries to load the crossdomain.xml in the following order: Flash Player尝试按以下顺序加载crossdomain.xml

  • port 843 of the server you passed to connect() (localhost:843 in your case) 您传递给connect()的服务器的端口843(在您的情况下为localhost:843)
  • the server:port you passed to connect() (localhost:9999 in your case) 您传递给connect()的server:port(在您的情况下为localhost:9999)

Now you have two options: 现在,您有两个选择:

  • Create an additional server on port 843 that just serves the crossdomain.xml 在端口843上创建一个仅用于服务crossdomain.xml的其他服务器
  • Serve the crossdomain.xml by your own server 由您自己的服务器提供crossdomain.xml

You'll find many useful information here . 您会在这里找到许多有用的信息。 Also you can find ready-to-use socket policy server software (for port 843) across the web. 您也可以在网上找到随时可用的套接字策略服务器软件(用于端口843)。 eg mod_socket_policy_server for Apache. 例如Apache的mod_socket_policy_server Tip: Google for 'socket policy server' 提示:适用于“套接字策略服务器”的Google

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM