# loadPolicyFile / crossdomain.xml problem!

**URL:** <https://forum.kirupa.com/t/loadpolicyfile-crossdomain-xml-problem/212818>\
**Category:** flash\
**Created:** [January 14, 2007, 6:54pm UTC](https://forum.kirupa.com/t/loadpolicyfile-crossdomain-xml-problem/212818 "2007-01-14T18:54:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZenBlender](https://avatars.discourse-cdn.com/v4/letter/z/a4c791/32.png) [@ZenBlender](https://forum.kirupa.com/u/ZenBlender)\
**Post date:** [January 14, 2007, 6:54pm UTC](https://forum.kirupa.com/t/loadpolicyfile-crossdomain-xml-problem/212818/1 "2007-01-14T18:54:46Z")

</div>

I am at the end of my rope. Can someone provide any insight into this loadPolicyFile() problem?

– I have a game server running on port 22777  
– I have my firewall routing all traffic from 80 to 22777 so both ports can be used identically  
– Port 82 is a HTTP port serving my crossdomain.xml file  
– Ideally I want clients to connect to port 80 as many users are restricted from other ports and cannot use my game

If you load [http://72.32.145.244:82/crossdomain.swf](http://72.32.145.244:82/crossdomain.swf) you will see it fails on port 80 and succeeds on port 22777. When it gets the “status:” message response, it is working correctly. My policy file is at [http://72.32.145.244:82/crossdomain.xml](http://72.32.145.244:82/crossdomain.xml)

By contrast, as a test, I do the exact same thing via PHP (connecting directly to port 80) and it works fine (I had to put it on another server so the firewall routes the external port): [http://infinitefish.com/temp/status\_test.php](http://infinitefish.com/temp/status_test.php)

The Flash side should load the crossdomain.xml policy file, then see that it is ok to connect to port 80 and do so. It does not. Below is the code for the Flash side:  
(FLA available at [http://72.32.145.244:82/crossdomain.fla](http://72.32.145.244:82/crossdomain.fla))

```auto
class crossdomain extends MovieClip{

      var mc:MovieClip;
      var socket:XMLSocket;
      
      var policy_port:Number = 82;
      var policy_url:String;
      var ip:String = "72.32.145.244";
      var ports:Array;
      var port_index:Number = 0;
      
      var connected_to:String = "";
      
      public function socket_send(msg:String){
            output("Sending: <font color=\"#FF8800\">"+msg+"</font>");
            socket.send(msg + String.fromCharCode(1) + String.fromCharCode(1) + String.fromCharCode(0));
      }
      public function output(msg:String){
            mc.out.htmlText += msg+"<br>";
      }
      public function socket_connect():Void{
            if (port_index < ports.length){
                  output("Attempting Connection to "+ip+":"+ports[port_index]);
                  socket.connect(ip, ports[port_index]);
            }
      }
      public function init():Void{
            policy_url = "http://"+ip+":"+policy_port+"/crossdomain.xml";
            
            ports = new Array();
            ports.push(80);
            ports.push(22777);
      
            var crossdomain_mc:MovieClip = this;
            socket = new XMLSocket();
            socket.onConnect = function(success){
              if (success){
                    crossdomain_mc.connected_to = crossdomain_mc.ip + ":" + crossdomain_mc.ports[crossdomain_mc.port_index];
                  crossdomain_mc.output("Connection Established");
                  crossdomain_mc.socket_send("status:");
              }else{
                  crossdomain_mc.output("<font color=\"#FF0000\">Connection Failed</font>");
                  crossdomain_mc.port_index++;
                  crossdomain_mc.socket_connect();
              }
          }
            socket.onData = function(str){
                  crossdomain_mc.output("Receiving: <font color=\"#FFFF00\">"+str+"</font>");
                  if (str.indexOf("players:")==0){
                        crossdomain_mc.output("<font color=\"#00FF00\">Test Successful on "+crossdomain_mc.connected_to+"</font>");
                  }
            }
            mc.out.text = "";
            
            output("[Note: Ports "+ports.join(", ")+" on "+ip+" are the same service]");
            output("Loading policy file from "+policy_url);
            
            System.security.loadPolicyFile(policy_url);
            
            socket_connect();
            
            
      }

      public function crossdomain(){
            mc = this;
            init();
      }
}

```

And here’s the PHP example connecting directly to 80, demonstrating that the services are identical:

```php
<?

$fp = @fsockopen("72.32.145.244", 80, $errno, $errstr, 10);
if (!$fp){
      echo '<font color="#880000">Server is down.</font>';
}else{      
      $cmd = 'status:'.chr(1).chr(1).chr(0);
      fwrite($fp, $cmd);
      $out = fread($fp, 256);            
      fclose($fp);            
      $out = str_replace(chr(0), "", $out);
      echo $out;
}

?>

```

Thanks very much for any insight! 🙂
