# How to Add XML Socket Policy Server?

**URL:** <https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113>\
**Category:** flash\
**Created:** [April 30, 2015, 10:18pm UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113 "2015-04-30T22:18:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Twisted4000](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Twisted4000](https://forum.kirupa.com/u/Twisted4000)\
**Post date:** [April 30, 2015, 10:18pm UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113/1 "2015-04-30T22:18:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [April 30, 2015, 11:35pm UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113/2 "2015-04-30T23:35:01Z")

</div>

Socket policy files are handled through the socket itself

More info here:  
[http://www.adobe.com/devnet/flashplayer/articles/socket\_policy\_files.html](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.

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [April 30, 2015, 11:40pm UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113/3 "2015-04-30T23:40:51Z")

</div>

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](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:

---

<div class="post-metadata">

**Author:** ![Twisted4000](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Twisted4000](https://forum.kirupa.com/u/Twisted4000)\
**Post date:** [April 30, 2015, 11:48pm UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113/4 "2015-04-30T23:48:36Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Twisted4000](https://avatars.discourse-cdn.com/v4/letter/t/f08c70/32.png) [@Twisted4000](https://forum.kirupa.com/u/Twisted4000)\
**Post date:** [May 1, 2015, 12:11am UTC](https://forum.kirupa.com/t/how-to-add-xml-socket-policy-server/633113/5 "2015-05-01T00:11:30Z")

</div>

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.
