PDA

View Full Version : Actionscript3 Socket Security Problem


MelloYello
05-26-2008, 01:54 AM
I'm a Java developer who just recently started playing with actionscript3 / flash and have been really enjoying.

I've started making a flash based game, and decided I wanted to add network support to it. To learn the initial ropes of the networking side of flash I decided to make a test page that would act as a chat room. Everything works perfect if I'm on my own box...but if its anywhere else a security sandbox error is throw and the swf doesn't connect. This flash security policy stuff is kicking my butt all over the place. :confused:

This is what I have...
-Tomcat running on port 80, serving the swf file
-a java socket server running on port 8080 that keeps all the connections and broadcasts messages as needed (for a new person entering / leaving the channel)

So I think I understand that since the swf is on port 80 from my IP that it needs a cross domain policy to be able to access the socket on port 8080. I know theres a socket or http based request methods, I would prefer to do it via http.

I put the file "crossdomain.xml" file in my root directory of the webserver, so that http://xx.xx.xx.xx/crossdomain.xml will actually display in the broswer.

I've put the load policy file directly before the socket creation / connection...ex:
Security.loadPolicyFile("http://xx.xx.xx.xx/crossdomain.xml");
mySocket = new Socket();

I type the url pointing to the html file flex created:
http://xx.xx.xx.xx/test.html
into IE to display the swf. Like I said...everything works perfectly opening multiple client connections on my computer. Anything off my computer (lan or internet) will not work though...everything comes back with a security error. (Error #2044: Unhandled SecurityErrorEvent:. text=Error #2048: Security sandbox violation).

Just in plain frustration I tried calling Security.allowDomain("*") which I dont think I need...but that too failed.

Any suggestions on how to get this http request policy working would be greatly appreciated...I guess in the mean time since I'm somewhat at a deadend I'll try the socket based policy request...but I would like to know what exactly I did wrong for the http one. Thanks.

MelloYello
05-26-2008, 11:46 PM
Just to give anyone else who might have a similar problem...I just finished the socket based policy retrieval system. Everything works as it should!

Tomcat on port 80 hosting the html/swf
socket server (apache Mina) running the chat listener on port 8080 and also on port 8081 for the flash policy file request from the swf.

All I had to do in the swf to load it is this line of code:

Security.loadPolicyFile("xmlsocket://xx.xx.xx.xx:8081");
mySocket = new Socket();
...
(add event listeners)
...
mySocket.connect("xx.xx.xx.xx", 8080);


...obviously xx.xx.xx.xx is my ip.

As far as the policy file...I just made a very simple one allowing any domain and all ports from 1024 and up:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" to-ports="*" />
</cross-domain-policy>

Just make sure you end your xml with a null char (per the flash policy protocol) and close the connection after you send it.

Anyway...I would still love to know if anyone has ideas why the HTTP policy request failed for me. I know it was the old way to do this and was included for backward compatability...but I thought it would still work just as easy. But I'm just glad I got this stupid policy stuff working...:)

tamarinda
10-14-2008, 09:44 AM
Hello!

I have exactly the same problem as you. I am trying the same, loading the policy file with xmlsocket as you did but I can't get it work.... How does your Java code look like??

thank you!!

tamarinda