Flash 客户端 XMLSocket 未连接到服务器

发布于 2024-07-29 19:36:18 字数 728 浏览 8 评论 0原文

我有一个 Flash 客户端,我想连接到服务器。 两者都使用 localhost 和端口 50000,因此不应该有任何跨域问题。 我还在发布设置中设置了仅访问网络。 当我调用 XMLSocket connect 时,服务器似乎获得了一个新连接。 但是,当 success=true 时,不会调用 XMLSocket.onConnect 回调。

关于可能出什么问题有什么想法吗?

这是用于创建套接字的 ActionScript。

 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;

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;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早茶月光 2024-08-05 19:36:18

这最终成为一个安全问题。 当使用 XMLSocket 时,Flash Player 增加了安全性。 Flash Player 现在在端口 843 上查找策略文件。另一种方法是使用调用 Security.loadPolicyFile() 让 swf 查找策略文件。 如果该文件存在并且所有安全设置都允许 XMLSocket,则会创建连接。

查看有关策略文件的 Adob​​e 文章和更多信息此处。 这是另一篇关于策略文件的好文章

这是最终对我有用的策略文件。 它根本没有限制性。 但是,我想我应该先让事情运转起来,然后再把它们做好。

<?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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文