简体   繁体   English

ActionScript Flex套接字和telnet

[英]Actionscript flex sockets and telnet

I am trying to make a flex application where it gets data from a telnet connection and I am running into a weird problem. 我正在尝试制作一个Flex应用程序,它从telnet连接获取数据,但我遇到了一个奇怪的问题。

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. ) 因此,如果在外壳中输入telnet localhost 8651我会收到xml,然后关闭连接(我得到了以下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! 无论如何,我在Flex上找到了一个简单的在线教程 ,它本质上是一个telnet客户端,人们希望它可以正常工作,但是一切都遵循Murphy的定律,而且任何方法都无效!

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! 当我连接到套接字没有任何反应时,即使连接或关闭处理程序也不会触发任何事件处理程序,如果我执行以下操作,则socket.connected返回false! I get no errors, try catch raises no exception. 我没有错误,尝试catch不会引发异常。 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. 是否有我不知道的有关telnet的信息,导致它无法正常工作。 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! 另一个有趣的事情是,我有一些执行相同操作的python代码,并且能够获取xml!

The following is the python code that works! 以下是有效的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)

So i ask you whats going wrong!!!!!! 所以我问你怎么了!!!!!! Is there some inherent problem with how flex handles sockets? flex如何处理套接字是否存在一些固有的问题?

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. 如果您将其作为嵌入网页中的Flash应用程序运行,则很可能是违反安全性的行为。

The XMLSocket.connect() method can connect only to computers in the same domain where the SWF file resides. XMLSocket.connect()方法只能连接到SWF文件所在的同一域中的计算机。 This restriction does not apply to SWF files running off a local disk. 此限制不适用于在本地磁盘上运行的SWF文件。 (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. (此限制与URLLoader.load()的安全规则相同。)若要连接到在SWF所在域以外的域中运行的服务器守护程序,可以在服务器上创建一个安全策略文件,以允许从特定领域。

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). 出于安全原因,您要连接的主机必须在端口943(或尝试连接的端口)上满足Flash套接字策略请求。 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 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. 在开发过程中,将SWF添加到安全沙箱中运行的文件列表中通常很方便,以减轻提供套接字策略文件的需要。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM