Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

sockets - Flash client XMLSocket not connecting to server

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
");
        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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...