问题描述
连接到Java(1.5)服务器上的套接字后,出现Flex 3沙箱错误#2048。服务器代码全是我的,即不在Apache下运行。 Flash Player 10.0 r32。序列如下...
Java服务器启动,侦听端口843用于策略文件请求,端口45455用于其他请求。
由Apache提供的Flex客户端(尽管如果从文件运行它,我会得到相同的结果系统),在主机上创建套接字连接:45455。
3 Flash Player从端口843请求策略文件。这是标准行为,新安全设置寻找主文件。不管是否指定了不同的策略文件,都会发生。
4我通过端口843从Java提供以下XML:
<?xml version =1.0?>
<!DOCTYPE跨域策略系统http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">
<跨网域政策>
< / cross-domain-policy>
5播放器将以下内容写入调试策略日志中...
OK:加载根级SWF:http://localhost/bst/BasicSocketTest.swf
OK:正在搜索< allow-access-从大于;在策略文件中授权数据从xmlsocket://192.168.2.3:45455处由请求者从http://localhost/bst/BasicSocketTest.swf
中加载数据:OK:接受策略文件:xmlsocket://192.168.2.3 :843
OK:请求者从http://localhost/bst/BasicSocketTest.swf请求xmlsocket://192.168.2.3:45455处的资源请求是允许的,因为策略文件位于xmlsocket://192.168.2.3: 843
6我使用<$ c $从客户端向端口45455上的服务器发送文本消息c> writeUTFBytes()和 flush()
(这是我自己的自制信息协议,并且在每一端都被正确处理) p>
REG / REGISTER; simon; Si
7在端口45455上侦听的Java服务器线程响应
REG:0 / REGISTER:SUCCESS; simon; Si
8 Flex客户端接收ProgressEvent,并且绑定到套接字的事件侦听器被调用。我处理这个消息(写到屏幕上的一个文本框)
9 Flash播放器抛出一个2048沙箱错误,套接字断开!这是在收到并处理成功消息之后。事实上大约是12秒后。 我试过用 我已经尝试了各种终止策略文件和策略文件内容的替代方法,包括故意错误只是为了看看Flash Player是否清醒。 我没有理由为什么我会抛出2048。我准确地在指定的主安全端口上提供一个套接字策略文件,玩家自己记录的是正确的。然后,套接字成功地发送并从服务器接收消息,其内容可用于我的代码。 有没有人有任何线索为什么会发生这种情况? Flash Player的bug? PS
Security.loadPolicyFile()$ c $在Flex客户端中,但新玩家安全性的现实是它基本上被忽略了。这些步骤是在发生套接字I / O操作之前不会发送策略请求。此时,玩家总是先前往端口843,首先查找主策略文件。如果它发现一个,它是宽容的,它不会进一步。
编辑
为了回应James Ward的要求注意,这里是整个错误信息:
$ p $ 错误#2048:安全沙箱冲突:http:// localhost / bst / BasicSocketTest .swf无法从192.168.2.3:45455加载数据。
我有一个精简的测试客户端,它为每个套接字事件都有一个处理程序,并向屏幕。这是它显示:
RequestPolicy:192.168.2.3:843
创建套接字:192.168.2.3:45455
连接:[Event type =connectbubbles = false cancelable = false eventPhase = 2]
发送:REG / REGISTER; [email protected]; Si
接收:REG:0 /REGISTER:SUCCESS;[email protected];Si/
错误#2048:安全沙箱冲突:安全沙箱冲突:事件类型=closebubbles = false cancelable = false eventPhase = http://localhost/bst/BasicSocketTest.swf无法从192.168.2.3:45455加载数据。
成功收到服务器的响应后立即触发close事件,但是错误#2048直到20秒后才出现。如果尝试在关闭之后发送进一步的消息,但在错误发生之前,Flash Player将抛出无效的套接字异常。
我有。
我可以提供客户端和服务器的完整源代码,如果任何人有兴趣的话。
我一直在本地进行测试,一切似乎工作正常,直到套接字被关闭。不应该关闭套接字吗?在将消息发送到Flex客户端之后,Java代码会执行:
_in.close();
_out.close();
_socket.close();然后,Flex客户端在下次尝试与套接字进行通信时,会收到沙盒违例。如果我再次创建一个新的套接字连接,然后发送和接收工作正常,紧随其后。但是一分钟之后,我得到另一个沙箱违规。我想知道Flash是否试图ping通套接字,并且因为它被关闭而抛出沙盒违例?
I get a Flex 3 sandbox error #2048 after connecting to a Socket on a Java (1.5) server. The server code is all mine, i.e. not running under Apache. Flash Player 10.0 r32.
The sequence is as follows...
1 Java server starts, listens on port 843 for policy file request and on port 45455 for my other requests.
2 Flex client served by Apache (although I get the same result if I run it from the file system), socket connection made on host:45455.
3 Flash Player requests policy file from port 843. This is the standard behaviour with the new security settings looking for a master file. It happens regardless of whether a different policy file has been specified.
4 I serve the following XML from Java through port 843:
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*" secure="false"/>
</cross-domain-policy>
5 The player writes the following into the debug policy log...
OK: Root-level SWF loaded: http://localhost/bst/BasicSocketTest.swf
OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://192.168.2.3:45455 by requestor from http://localhost/bst/BasicSocketTest.swf
OK: Policy file accepted: xmlsocket://192.168.2.3:843
OK: Request for resource at xmlsocket://192.168.2.3:45455 by requestor from http://localhost/bst/BasicSocketTest.swf is permitted due to policy file at xmlsocket://192.168.2.3:843
6 I send a text message from the client to the server on port 45455 using writeUTFBytes()
and flush()
(this is my own home-baked message protocol, and is correctly processed at each end)
REG/REGISTER;simon;Si
7 Java server thread listening on port 45455 responds with
REG:0/REGISTER:SUCCESS;simon;Si
8 The Flex client receives a ProgressEvent and the event listener I bound to the socket gets called. I process the message (write it to a text box on the screen)
9 The Flash player throws a 2048 sandbox error and the socket is disconnected! This is after the message is received and processed successfully. In fact it is about 12 seconds after. Nothing else works through the socket.
I have tried explicitly loading a policy file with a call to Security.loadPolicyFile()
in the Flex client, but the reality of the new player security is that it is basically ignored. The steps are that the policy request will not get sent until a socket i/o operation occurs. At that point the player always goes to port 843 first looking for a master policy file. If it finds one, and it is permissive, it goes no further.
I have tried a variety of alternative ways of terminating the policy file and policy file contents, including deliberate errors just to see if the Flash Player is awake.
I can see no reason why I would have a 2048 being thrown. I accurately serve a socket policy file on the designated master security port, which the player itself logs as correct. The socket then successfully sends and receives a message from the server the contents of which are available to my code.
Does anyone have any clue why this may be happening? Flash Player bug?
P.S. Please don't tell me to use BlazeDS or LCDS or Granite, or something else as a server, I'm looking for a solution to this problem, not a redesign. And please don't ask me to use an XMLSocket instead - I tried that and get exactly the same result. I have chosen my architecture carefully and deliberately and I want a binary socket.
EDITIn response to James Ward's request in his comment, here is the entire error message:
Error #2048: Security sandbox violation: http://localhost/bst/BasicSocketTest.swf cannot load data from 192.168.2.3:45455.
I have a stripped down test client which has a handler for each socket event and outputs a message to the screen. This is what it shows:
RequestPolicy: 192.168.2.3:843
Create Socket: 192.168.2.3:45455
Connect: [Event type="connect" bubbles=false cancelable=false eventPhase=2]
Sending: REG/REGISTER;[email protected];Si
Receiving: REG:0/REGISTER:SUCCESS;[email protected];Si/
Close: [Event type="close" bubbles=false cancelable=false eventPhase=2]
Error #2048: Security sandbox violation: http://localhost/bst/BasicSocketTest.swf cannot load data from 192.168.2.3:45455.
The close event is fired immediately after successfully receiving a response from the server, however the Error #2048 does not appear until about 20 seconds later. If I try and send a further message after close, but before the error, the Flash Player throws an invalid socket exception.
I have logged a bug at Adobe about this.
I can provide full source code of both client and server if anyone is interested.
解决方案 I've been testing this locally and everything seems to be working fine until the socket gets closed. Shouldn't the socket not get closed? After the message is sent to the Flex client, the Java code does:
_in.close();
_out.close();
_socket.close();
Then the Flex client gets the sandbox violation the next time it tries to communicate with the socket. If I create a new socket connection again then send and receive works fine, followed by a close. But after a minute or so I get another sandbox violation. I wonder if Flash is trying to ping the socket and since it's closed it throws the sandbox violation?
这篇关于为什么Flash Player在这种情况下会抛出一个沙盒错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!