Connecting Flash to a Server

Subscribe to Connecting Flash to a Server 12 posts, 4 voices

 
avatar for pianomanDylan pianomanDylan 8 posts

Ok here’s the deal: I’m running an apache server so I can test web applications by going to http://localhost I have a program in java that, when running, will accept socket connection requests and handle them, relaying messages back and forth. I have a .swf that tries to open a connection.

When I open the swf as a file right from my computer, the security sandbox says it’s in “LocalTrusted” mode, and connections happen, and the whole thing functions exactly the way I want. But when I open up localhost/xmlSocket.swf, the security sandbox says it is “Remote”, and the connection fails outright.

I’ve been searching on Google for the past TWO DAYS and have determined (I think) that the cause was that I had no policy file anywhere. Well now I have one, called ‘crossdomain.xml’, with this in it:

(the forum formatting is screwing up my XML data. The allow-access thing has “domain”, then ”=”, and an asterisk in quotes, before the ending slash.)

<?xml version=”1.0”?> <cross-domain-policy> <allow-access-from /> </cross-domain-policy>

I also put a loadPolicyFile request in the first line of my code in the swf.

Somehow, it’s STILL not working, and I am baffled, exhausted, and aggravated, and have no idea why it refuses to work. If anyone can help me or if you have any ideas that might help, I’d be extremely grateful!

 
avatar for ExtremePopcorn ExtremePopcorn 839 posts

Try this?

<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*" />
    <allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

By the way, nice avatar. Billyfred and Unproductive need to get that. It’d go well with their current ones.

 
avatar for pianomanDylan pianomanDylan 8 posts

Thanks, I like my avatar.

I tried putting exactly that in my crossdomain.xml file, but still no change :( Any other ideas?

Does my java program have to actually send the message initially when it first accepts the connection? Or does Apache automatically know what to do?

 
avatar for pianomanDylan pianomanDylan 8 posts

Okay so I looked long and hard at that dang article that Adobe has (which has been completely unhelpful except for the following…) and found out how to get log for my policy files. Apparently it’s finding my file, but ignoring it due to “incorrect syntax”. Here’s a snippet from the log…

Warning: [strict] Ignoring policy file at xmlsocket://localhost:9999 due to incorrect syntax. See http://www.adobe.com/go/strict_policy_files to fix this problem. Error: SWF from http://localhost/xmlSocket.swf may not connect to a socket in its own domain without a policy file. See http://www.adobe.com/go/strict_policy_files to fix this problem.

I visited the specified link, but was automatically redirected to the main article, full of totally useless information. All I found were things that could cause this error, none of which I’m noticing in my own xml file! Here’s the file contents, note that I’ve tried several. If anyone has a working policyfile, PLEASE could you post it so I can see what the parser wants me to write? <?xml version=”1.0” encoding=”UTF-8”?> <cross-domain-policy> <site-control /> <allow-access-from>” headers=”*”/> </cross-domain-policy>

Asterisks in quotes are getting ignored.. could someone also let me know how to get the code/quote block in these forums?

 
avatar for Jabor Jabor 2801 posts

Use <pre> tags to format code for the forums.

 
avatar for bengarney bengarney 27 posts

Dunno if you’re having formatting issues due to the forums eating it but you have:

<?xml version=”1.0” encoding=”UTF-8”?>
<cross-domain-policy>
    <site-control />
    <allow-access-from>” headers=”*”/>
</cross-domain-policy>

And the allow-access-from line is definitely wrong. But that might be an artifact of the forums.

 
avatar for bengarney bengarney 27 posts

One thing that’s usually a gotcha for me is that Flash’s XML parser wants quotes around every attribute’s value, not just ones that have strings. ie <foo /> isn’t allowed.

 
avatar for ExtremePopcorn ExtremePopcorn 839 posts

Well try looking at some of the comments from this site. I thought this one might be useful:

This is the exact crossdomain.xml file I have on my  server:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*" />
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

If it is your Flash app you are developing, you will need to also in the Actionscript code specify the crossdomain file like so:
Security.loadPolicyFile("http://(your url)/crossdomain.xml"); 

And if that still doesn’t work, then try this:

http://www.adobe.com/devnet/flashplayer/article…

 
avatar for pianomanDylan pianomanDylan 8 posts
Thanks for the responses, guys. Here’s what I currently have:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*" />
<allow-http-request-headers-from domain="*" headers="*"/>
</cross-domain-policy>

And it still doesn’t work. I also tried the one from ExtremePopcorn’s post, as well as the one from the article he linked me to. Niether of them worked for me! (The article’s example would deny me access anyway, but it still left me with the “rejected due to bad syntax” message.)

Could it have something to do with the fact that I’m serving the files from localhost instead of an actual domain name? Or could it be some deeper problem, such as the parser?

 
avatar for ExtremePopcorn ExtremePopcorn 839 posts

I’m just taking a wild guess here, but try changing the port number from 9999 to 1024 or below.

 
avatar for pianomanDylan pianomanDylan 8 posts

Well I assumed that wouldn’t work because Flash won’t connect to any port 1024 or below, but here’s the errors that appear in the log as a result of using connect(“localhost”,9999);

OK: Root-level SWF loaded: <a href="http://localhost/xmlServe/xmlSocket.swf">http://localhost/xmlServe/xmlSocket.swf</a>
OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://localhost:99 by requestor from <a href="http://localhost/xmlServe/xmlSocket.swf">http://localhost/xmlServe/xmlSocket.swf</a>
Warning: Domain localhost does not specify a meta-policy.  Applying default meta-policy 'all'.  This configuration is deprecated.  See <a href="http://www.adobe.com/go/strict_policy_files">http://www.adobe.com/go/strict_policy_files</a> to fix this problem.
OK: Policy file accepted: <a href="http://localhost/crossdomain.xml">http://localhost/crossdomain.xml</a>
Error: Request for resource at xmlsocket://localhost:99 by requestor from <a href="http://localhost/xmlServe/xmlSocket.swf">http://localhost/xmlServe/xmlSocket.swf</a> has failed because the server cannot be reached.

The meta-policy deal sounds new to me. Any ideas about that?

Or possibly the java program that handles the sockets is accidentally sending out data that Flash thinks is the policy file? That may explain why none of my changes to the xml document are working…

 
avatar for pianomanDylan pianomanDylan 8 posts

SUCCESS!! My searches turned up a new site, and this one had an example of a Java-based Policy Server.

http://www.blog.lessrain.com/as3-java-socket-co…

By running that and my own message relay server concurrently, and in my flash, sending a policy request, then trying to connect to the Policy Server, then connecting to the Relay server afterwards, the policy file is accepted, and a connection is made to my port 9999 server!

Turns out that my port 9999 server was sending data that got interpreted as a policy file (even though it was supposed to be a welcome-to-chat message), and then not making a connection because the “policy file” was ignored! Fancy that.