views:

1463

answers:

2

I have a Flash client that I want to connect to a server. Both are using localhost and port 50000 so there shouldn't be any cross-domain problems. I also set Access Network Only in the publishing settings. When I call the XMLSocket connect, the server seems to get a new connection. But, the XMLSocket.onConnect callback is not called with success=true.

Any ideas on what may be wrong?

Here's the ActionScript for creating the socket.

 function myOnConnect(success) {
    if (success) {
     trace ("Connection succeeded!")
     inputText.text = "open";
//   socket.send("1\n");
     gotoAndPlay(2);
    } else {
     trace ("Connection failed!")
     inputText.text = "failed";
    }
}


btnConnect.onRelease = function()
{
    inputText.text = "started";


    result = socket.connect("localhost", 50000);


}

socket = new XMLSocket();
socket.onConnect = myOnConnect;
+2  A: 

This ended up being a security problem. The Flash Player has added security when a XMLSocket is used. The Flash Player now looks for a policy file on port 843. An alternative is to have the swf look for the policy file using the call Security.loadPolicyFile(). If the file exists and all the security settings permit the XMLSocket, then the connection is created.

Check out the Adobe article on Policy files and more info here. This is another good article about policy files.

Here is the policy file that finally worked for me. It is not restrictive at all. But, I figured I get things working and then make them right.

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">

<!-- Policy file for xmlsocket://socks.example.com -->
<cross-domain-policy> 

   <!-- This is a master socket policy file -->
   <!-- No other socket policies on the host will be permitted -->
<!--   <site-control permitted-cross-domain-policies="all"/> -->

   <!-- Instead of setting to-ports="*", administrator's can use ranges and commas -->
   <!-- This will allow access to ports 123, 456, 457 and 458 -->
   <allow-access-from domain="*" to-ports="*" secure="false"/>

</cross-domain-policy>
zooropa