我知道这已经被触及了很多,但是,尽管如此,我还是没有得到它。如果你们能忍受我:(
所以,我有这个代码:
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();
}
我做了很多测试,我会尽力整齐地总结一下。
如果直接从Flash运行(ctrl + enter)并且套接字服务器脱机且权限设置为网络并且该行mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityHandler) COMMENTED OUT
输出如下:
错误#2044未处理的安全性error.txt =错误#2048安全沙箱违规文件///G|/flash%20Stuff/socketClientNetwork.swf无法从sockethost加载数据:9999 at socketClientNetwork_fla :: maintimeline / frame 1 {} < / p>
如果从SWF 运行且套接字服务器脱机且权限设置为网络并且该行(来自上方)是未注明 输出如下:
开始!
内部连接到服务器
安全错误
如果直接从 Flash (ctrl + enter)和套接字服务器脱机运行,权限设置为本地和行mySocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityHandler) COMMENTED OUT
输出如下:
错误#2044未处理的安全性error.txt =错误#2048安全沙箱违规文件///G|/flash%20Stuff/socketClientLocal.swf无法从sockethost加载数据:9999在socketClientLocal_fla :: maintimeline / frame 1 {} < / p>
如果从 SWF 运行且套接字服务器和套接字服务器 OFFLINE 且权限设置为本地和行(如上所述)未评论
SWF :: Online :: Local :: Commented
FLA :: Online :: Local :: Uncommented
SWF ::在线::网络::评论
FLA ::在线::网络::未注释
答案 0 :(得分:0)
您必须将文件系统上的swf移动到本地Web服务器的文档根文件夹或其子文件夹,然后键入浏览器地址栏:
http://localhost/socketClientLocal.swf
而不是
file:///G|/flash%20Stuff/socketClientLocal.swf
此外,您还必须创建一个名为crossdomain.xml
的所谓“套接字策略文件”:
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="localhost" toports="*"/>
</cross-domain-policy>
开启connect()
Flash Player首先尝试加载此文件。如果加载失败或设置限制访问,Flash播放器也会触发您遇到的安全错误。
Flash Player尝试按以下顺序加载crossdomain.xml
:
connect()
的服务器的端口843(在您的情况下为localhost:843)connect()
的服务器端口(在您的情况下为localhost:9999)现在您有两个选择:
您会找到许多有用的信息here。您还可以在Web上找到可立即使用的套接字策略服务器软件(用于端口843)。例如Apache的mod_socket_policy_server。提示:Google for“socket policy server”
祝你好运!