Actionscript Flex 套接字和 telnet

发布于 2024-08-20 08:03:20 字数 1062 浏览 0 评论 0原文

我正在尝试制作一个 Flex 应用程序,它从 telnet 连接获取数据,但我遇到了一个奇怪的问题。

简单介绍一下,我想从通过套接字公开数据的进程中读取数据。因此,如果在 shell 中输入 telnet localhost 8651,我会收到 xml,然后关闭连接(我得到以下信息:Connection returned byforeign host。)

无论如何,我找到了一个Flex 的简单在线教程,本质上是一个 telnet 客户端,人们希望它能够工作,但一切都遵循墨菲定律,但没有任何效果!

现在,我在每个事件处理程序以及我能想到的所有地方都打印了消息。当我连接到套接字时,没有任何反应,即使连接或关闭处理程序也不会触发任何事件处理程序,如果我执行以下操作,socket.connected 将返回 false!我没有收到任何错误,try catch 也没有引发异常。我不知道出了什么问题?

        socket.connect(serverURL, portNumber);
        msg(socket.connected.toString());

是否有关于 telnet 的事情我不知道并且导致它无法工作。更有趣的是为什么没有一个事件被触发。

另一个有趣的事情是我有一些 python 代码可以做同样的事情并且它能够取回 xml!

下面是可以运行的Python代码!

  def getStats(host, port):
 sock = socket.socket()
 sock.connect((host, port))
 res = sock.recv(1024*1024*1024, socket.MSG_WAITALL)
 sock.close()
 return statFunc(res)

所以我想问你这是怎么了!!!! flex 处理套接字的方式是否存在一些固有的问题?

I am trying to make a flex application where it gets data from a telnet connection and I am running into a weird problem.

To give a brief introduction, i want to read data from a process that exposes it through a socket. So if in the shell i type telnet localhost 8651i receive the xml and then the connection is closed (I get the following Connection closed by foreign host.)

Anyway i found a simple tutorial online for flex that essentially is a telnet client and one would expect it to work but everything follows Murphy's laws and nothing ever works!

Now i have messages being printed in every event handler and all places that i can think off. When i connect to the socket nothing happens, no event handler is triggered even the connect or close handler and if i do the following the socket.connected returns false! I get no errors, try catch raises no exception. I am at a loss as to whats going wrong?

        socket.connect(serverURL, portNumber);
        msg(socket.connected.toString());

Is there something about telnet that i do not know and its causing this to not work. Whats more interesting is why none of the events get fired.

Another interesting thing is that i have some python code that does the same thing and its able to get the xml back!

The following is the python code that works!

  def getStats(host, port):
 sock = socket.socket()
 sock.connect((host, port))
 res = sock.recv(1024*1024*1024, socket.MSG_WAITALL)
 sock.close()
 return statFunc(res)

So i ask you whats going wrong!!!!!! Is there some inherent problem with how flex handles sockets?

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

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

发布评论

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

评论(2

埋葬我深情 2024-08-27 08:03:20

您在什么安全沙箱中运行它?如果您将其作为嵌入网页中的 Flash 应用程序运行,那么这很可能是安全违规。

XMLSocket.connect()方法可以
仅连接到同一计算机
SWF 文件所在的域。
此限制不适用于 SWF
从本地磁盘运行的文件。 (这
限制与
URLLoader.load() 的安全规则。)
连接到正在运行的服务器守护程序
在一个域以外的域中
SWF 驻留,您可以创建一个
服务器上的安全策略文件
允许从特定的访问
域。

What security sandbox are you running this in? if you are running this as a flash application embedded in a web page then this is most likely a security violation.

The XMLSocket.connect() method can
connect only to computers in the same
domain where the SWF file resides.
This restriction does not apply to SWF
files running off a local disk. (This
restriction is identical to the
security rules for URLLoader.load().)
To connect to a server daemon running
in a domain other than the one where
the SWF resides, you can create a
security policy file on the server
that allows access from specific
domains.

旧伤慢歌 2024-08-27 08:03:20

出于安全原因,您要连接的主机必须在端口 943(或您尝试连接的同一端口)上提供 Flash 套接字策略请求。本页向您展示如何在您尝试连接的服务器上进行设置:

http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

在开发过程中,将 SWF 添加到在安全沙箱中运行的文件列表中通常很方便,以减轻需要提供套接字策略文件。

http://www.macromedia.com/support/documentation/ en/flashplayer/help/settings_manager04.html

For security reasons, the host you're connecting to must serve Flash socket policy requests on port 943 (or on the same port on which you're attempting your connection). This page shows you how to set this up on the server that you're attempting to connect to:

http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

During development it is often convenient to add your SWF to the list of files that run in the secure sandbox to alleviate the need to have a socket policy file served.

http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

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