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;
zooropa
  • 3,929
  • 8
  • 39
  • 61
  • 1
    Looks fine, but I'm suspicious about "localhost". Try using null (per the ActionScript Docs for a "same machine" connection) and see if that works. – Michael Todd Jul 30 '09 at 01:50
  • I run it in the Flash debugger and it connects immediately. I wonder if there is a security setting I need for it to work in a browser. It doesn't work in IE or Firefox. – zooropa Jul 30 '09 at 01:54
  • Just for funzies, I also tried switching the Publishing setting to Access Local Files only. Didn't work. – zooropa Jul 30 '09 at 01:57
  • Using null for same machine didn't work. Thanks for the idea though. – zooropa Jul 30 '09 at 02:00
  • Never mind. If you can connect via the Flash debugger, connectivity shouldn't be an issue, though security still might be. – Michael Todd Jul 30 '09 at 02:12
  • After digging around the net, I found this on socket policy files. I think this is an issue. http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html – zooropa Jul 30 '09 at 02:28
  • I found this article about policy files too. http://gruchalski.com/2009/06/11/xmlsocket-send-socket-writeutfbytes-doesnt-work/ – zooropa Jul 30 '09 at 02:40
  • That's annoying (and weird that it works in the debugger but not "live"). Let me know if setting things up this way works (by answering the question, of course). – Michael Todd Jul 30 '09 at 02:57

1 Answers1

4

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
  • 3,929
  • 8
  • 39
  • 61