How to Add XML Socket Policy Server?

So I’m making a TCP Socket Flash game, and I got it connected and working alright, it works fine over the LAN, but when I try to play with someone on a different router using Hamachi, the first message sends fine, but every additional message just throws the “Operation Attempted On Invalid Socket” error and it disconnects them. I’m assuming this is
due to the socket policy server. I THOUGHT I added one correctly… but I guess I didn’t? This is my code in the AIR server:

var security:URLLoader = new URLLoader();
var securityContent:XML;security.load(newURLRequest("security-app.xml"));
security.addEventListener(Event.COMPLETE, loadComplete);

function loadComplete(e:Event):void {
securityContent = XML(security.data);
securityContent.ignoreWhite = true;
security.removeEventListener(Event.COMPLETE, loadComplete);
}
addEventListener(Event.ENTER_FRAME, loadComplete);

And this is the “security-app.xml” file:

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

Is there something I did wrong? I’ve been looking around allover the internet for days but I can’t seem to get an answer. Thanks.

Socket policy files are handled through the socket itself

More info here:
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

The request for a policy file is very simple: Flash Player sends the string <policy-file-request/> followed by a NULL byte to the port where it is requesting a policy file; no more, no less. Flash developers cannot modify the string that is sent. In return, Flash Player expects to receive the socket policy file as text. Once Flash Player receives the socket policy file, it closes the connection and opens a new connection if the policy file approves the request.

If both your server and clients are using AIR, then you don’t need to worry about or use policy files. If your clients are using Flash Player, then your AIR server needs to send that XML policy over the socket to each client when they send the Flash Player mandated <policy-file-request/>\0 string.

Right now it looks like your server is trying to load a policy file for itself from itself…which won’t accomplish much. And your XML is malformed since it starts with a misplaced hyphen.

This article is pretty much the gold standard for how to deal with socket policy files, if you need them: http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html


The “Operation Attempted On Invalid Socket” error you’re seeing means the socket has been closed. If your clients are using Flash Player, then the error implies that your server failed to respond to Flash Player’s request for a socket policy file, and immediately closed the socket because you didn’t meet the right security requirements.

If your game clients are just AIR apps, then something else is messing with your socket connections. Hard to say what with this amount of info.


Edit: Curse you @senocular :evil:

1 Like

It is an AIR server with Flash clients attempting to connect to it. Oh and I didn’t even see that misplaced hyphen, lol. Well thanks I’ll check out the link…

Alright, so I pasted that code into the Flash client and the XML document is also in the same directory as it… is that all I needed to do? I’ve seen that link before but it doesn’t really exactly tell me all codes to use as far as I can see, It also mentions other methods like Python?? I’m just using Flash and AIR. All I want is to know what code I’m supposed to put into the client and what code to put in the AIR server.