views:

364

answers:

2

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?

A: 

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.

sean
well at the moment everything is on the same machine. And iam not using the XMLSocket but the Socket socket.As for the security sandbox I am not sure. this is my first attempt at flex. Even if it were a security issue shouldn't i be getting some sort of errors or exceptions?
MAC
Well i could make a cross domain policy file but iam not sure where to put it. Like i said everything is on the harddisk.
MAC
A: 

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

John McCann