Actionscript Flex 套接字和 telnet
我正在尝试制作一个 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 8651
i 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您在什么安全沙箱中运行它?如果您将其作为嵌入网页中的 Flash 应用程序运行,那么这很可能是安全违规。
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.
出于安全原因,您要连接的主机必须在端口 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