开发者

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.

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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜