无法使用 AS3.0 XMLSocket 连接到服务器

发布于 2024-08-20 17:18:11 字数 647 浏览 5 评论 0原文

我有一个用 Python 编写的服务器,我正在尝试通过 Flash 的 XMLSocket 连接到它。我确信该服务器工作正常,因为我已成功地将其与多个非 Flash 客户端应用程序一起使用。目前,我只想使用本地磁盘上的 SWF 连接到远程服务器。据我了解,这意味着我不需要安全策略文件,因为 SWF 不在另一个域中。我还确认该文件的安全沙箱属性已设置为本地受信任,因此 SWF 应该能够连接到服务器并从中检索数据。以下是 AS 文件中的重要代码:

var xmlSocket:XMLSocket = new XMLSocket();
public function MainLogic() {
    xmlSocket.addEventListener(DataEvent.DATA, onDataReceived);
    xmlSocket.connect('XXX.XXX.XXX.XXX', XXXX);
}
public function onDataReceived(event:DataEvent):void {
    helloText.text = 'data received'
}

服务器被编程为在建立连接后立即发送字符串“hello\0”。但如果成功发生,则动态文本框中的默认文本应替换为字符串“收到的数据”,但这种情况没有发生。即使 SWF 文件位于本地,我是否仍然需要策略文件?

I have a server that I have written in Python and I'm trying to connect to it via Flash's XMLSocket. I know for sure that this server is working properly as I have used it successfully with multiple non-Flash client applications. For right now, I just want to connect to the remote server with an SWF residing on my local disk. From what I understand, this means that I do not need a security policy file since the SWF is not in another domain. I have also confirmed that the security sandbox property of the file is set to local-trusted, so the SWF should be able to connect to servers and retrieve data from them. Here's the important code from the AS file:

var xmlSocket:XMLSocket = new XMLSocket();
public function MainLogic() {
    xmlSocket.addEventListener(DataEvent.DATA, onDataReceived);
    xmlSocket.connect('XXX.XXX.XXX.XXX', XXXX);
}
public function onDataReceived(event:DataEvent):void {
    helloText.text = 'data received'
}

The server is programmed to send the string 'hello\0' as soon as the connection is made. But if this was happening successfully, then the default text in the dynamic textbox should be replaced with the string 'data received', which is not happening. Is it possible that I still need the policy file even though the SWF file is local?

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

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

发布评论

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

评论(3

慵挽 2024-08-27 17:18:12

确保为所有潜在的 错误添加侦听器events,这将消除调试中的大量猜测。
我建议更改 示例livedocs 来测试一下。他们设置了这些事件:

xmlSocket.addEventListener(Event.CLOSE, closeHandler);
xmlSocket.addEventListener(Event.CONNECT, connectHandler);
xmlSocket.addEventListener(DataEvent.DATA, dataHandler);
xmlSocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
xmlSocket.addEventListener(ProgressEvent.PROGRESS, progressHandler);
xmlSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

Make sure you add in listeners for all potential error events, that will take alot of the guesswork out of debugging.
I'd recommend changing up the example from the livedocs to test things out. They set up these events:

xmlSocket.addEventListener(Event.CLOSE, closeHandler);
xmlSocket.addEventListener(Event.CONNECT, connectHandler);
xmlSocket.addEventListener(DataEvent.DATA, dataHandler);
xmlSocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
xmlSocket.addEventListener(ProgressEvent.PROGRESS, progressHandler);
xmlSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
温暖的光 2024-08-27 17:18:12

我会采用葡萄柚的策略来看看你遇到了什么错误。

我的猜测是这是一个安全错误。我认为在尝试通过套接字连接时您始终需要一个策略文件服务器。

I'd go with grapefrukt's strategy to see what error you're getting.

My guess is that it's a security error. I think you always need a policy file server when attempting to connect via sockets.

昇り龍 2024-08-27 17:18:12

我用未注册的帐户发布了这个问题,因此我无法选择最佳答案或评论,但基本上添加事件处理程序效果很好。这确实是一个安全错误,因此策略文件可能是问题所在。然而,我发现一个更简单的解决方案是只修改 Flash 播放器上的设置,以始终允许某些文件夹或文件的网络访问。我修改了此网站的设置:http://www. Macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

I posted this question with an unregistered account so I can't choose a best answer or comment, but basically adding the event handlers worked perfectly. It did turn out to be a security error, so the policy file may have been the issue. However, I found a much simpler solution is to just modify the settings on the flash player to always allow network access for certain folders or files. I modified the settings with this site: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

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