dongou2019 2012-12-23 00:10
浏览 49

在Wamp:Sandbox Violation上使用针对AS3的PHP套接字服务器

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

The output is as Followed:

  • Started!
  • Inside Connect to Server
  • Inside xmlsocket
  • Inside 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{}

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:

  • 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

The output is as follows:

  • Started!
  • Inside Conenct to Server
  • Inside 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{}

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

  • Started!
  • Inside Connect to Server
  • Security Error

SWF :: Online :: Local :: Commented

  • Started!
  • Inside Connect to Server
  • Security Error

FLA :: Online :: Local :: Uncommented

  • Started!
  • Inside Connect to Server
  • Inside xmlsocket
  • Inside connect to Server
  • Connection Established

SWF::Online::Network::Commented

  • Started!
  • Inside Connect to Server
  • Security Error

FLA::Online::Network::Uncommented

  • Started!
  • Inside connect to server
  • Inside xml socket
  • Inside connect
  • Server Connection Established
  • 写回答

1条回答 默认 最新

  • dongyun4010 2012-12-23 00:22
    关注

    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:

    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:

    <?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. If it fails to load or the settings restrict access, flash player triggers the security error you encountered too.

    Flash Player tries to load the crossdomain.xml in the following order:

    • port 843 of the server you passed to connect() (localhost:843 in your case)
    • the server:port you passed to connect() (localhost:9999 in your case)

    Now you have two options:

    • Create an additional server on port 843 that just serves the crossdomain.xml
    • Serve the crossdomain.xml by your own server

    You'll find many useful information here. Also you can find ready-to-use socket policy server software (for port 843) across the web. e.g. mod_socket_policy_server for Apache. Tip: Google for 'socket policy server'

    Good Luck!

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)