如何让我的PHP套接字服务器向Flash客户端发送策略文件?

问题描述 投票:1回答:5

我的Flash游戏需要连接到我的PHP套接字服务器。由于安全性,在尝试连接时必须将策略文件发送到闪存客户端。

以下是我所做的。

在Actionscript / Flex 3 / Flash中:

Security.loadPolicyFile("http://[SERVER.IP]:9000/crossdomain.xml");
socket.connect(hostName, port); //connect to the socket
[rest of original code]

为了使套接字服务器响应请求,我将以下内容添加到服务器:

elseif (preg_match("/policy-file-request/i", $buffer) or preg_match("/crossdomain/i", $buffer)) {
                    socket_write($socket, '<?xml version="1.0"?><cross-domain-policy><site-control permitted-cross-domain-policies="all"/><allow-access-from domain="*" to-ports="9000" /></cross-domain-policy>');
                    unset($read_sockets[array_search($socket, $read_sockets)]);
                    socket_shutdown($socket, 2);
                    socket_close($socket);

但是,我收到以下错误:“由于缺少Content-Type而忽略(URL)的策略文件。”所以,我试图通过在我的xml代码上方添加一个标题来解决这个问题:

socket_write($socket, "Content-Type: text/xml\n");

不幸的是,我仍然得到同样的错误。我是否以错误的方式提供内容类型?

actionscript-3 sockets flex3 content-type policy
5个回答
2
投票

试着发送:

HTTP/1.1 200 OK\r\nContent-Type: text/xml\r\n\r\n

确保在此之前没有发送任何内容。另外,在套接字关闭之前发送\r\n


3
投票

如果要使用以下内容,则需要返回有效的HTTP响应:

Security.loadPolicyFile("http://[SERVER.IP]:9000/crossdomain.xml");

如果闪存将连接到您的PHP套接字服务器,只需跳过上面的行,它将尝试端口本身并期望原始数据而不是HTTP响应。


2
投票

您可以使用Security.loadPolicyFile()从服务器的任何端口加载策略文件...也许您应该只在端口80上按http服务,从那里加载它然后连接到服务器...

此外,默认情况下,我认为flashplayer 9(从一些次要版本向上)默认发送一个策略文件请求到端口943 ...所以你可能会把服务器放在那里,为此...

一点注意事项:PHP从来没有设计用于套接字服务器,并且不是很擅长......如果可以,尝试使用Java或NekoVM,可以使用Haxe ...还有Haxe远程处理,以及ThreadedRemotingServer你可能会感兴趣...有一些关于Haxe网站的好的和清晰的教程......


1
投票

在Content-Type之后尝试使用\ r \ n。

socket_write($socket, "Content-Type: text/xml\r\n");

你不应该在端口843上使用xmlsocket吗?


1
投票
if(trim($buffer) == '<policy-file-request/>') {
$policy_file =
    '<'.'?xml version="1.0" encoding="UTF-8"?'.'>'.
    '<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">'.
        '<allow-access-from domain="*" to-ports="*" secure="false" />'.
        '<site-control permitted-cross-domain-policies="master-only" />'.
    '</cross-domain-policy>';

socket_write($socket, $policy_file.chr(0));
}

对我来说工作正常,客户端将请求策略文件,断开连接,然后在收到策略文件后重新连接

© www.soinside.com 2019 - 2024. All rights reserved.