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