Flash通过独立的Flash Player连接到套接字,但不在浏览器中连接

时间:2015-08-18 15:24:07

标签: actionscript-3 sockets flash air

由于某种原因,我一直在开发的Flash应用程序突然失去了通过Socket类维护与服务器的连接的能力。此问题似乎只发生在Web浏览器中,并且在使用独立Flash播放器运行应用程序时工作正常。策略文件如下;

public function Main():void 
{
    policyServer.bind(843);
    policyServer.addEventListener(Event.CONNECT, policyConnection);
    policyServer.listen();
}

public function policyConnection(e:ServerSocketConnectEvent)
{
    var policySocket:Socket = e.socket;
    policySocket.writeUTFBytes(policy);
    policySocket.flush();
    policySocket.close();
    policySocket = null();
}

public var policy:String = '<?xml version="1.0"?><cross-domain-policy>' +
'<site-control permitted-cross-domain-policies="master-only"/>' +
'<allow-access-from domain="*" to-ports="*" />' +
'</cross-domain-policy>\x00';

这在过去一直有效,因为它能够在独立的Flash播放器中运行,似乎不是导致问题的原因。

在服务器应用程序(使用AIR框架中的ServerSocket类构建)中,以下跟踪表明客户端能够连接到主服务器,但很快就断开连接;

public function clientConnection(e:ServerSocketConnectEvent)
{
    trace("Client connected to main server."); // this is outputted
    var clientSocket:Socket = e.socket;
    clientSocket.addEventListener(ProgressEvent.SOCKET_DATA, incomingPackets);
    clientSocket.addEventListener(Event.CLOSE, removeClient);
}

public function removeClient(e:Event)
{
    for (var i = 0; i < connectedClients.length; i++)
    {
        if (connectedClients[i][0] == e.target)
        {
            trace("User disconnected"); // this is outputted straight after
        }
    }
}

有什么想法吗?

0 个答案:

没有答案