views:

84

answers:

3

I have a server that I have written in Python and I'm trying to connect to it via Flash's XMLSocket. I know for sure that this server is working properly as I have used it successfully with multiple non-Flash client applications. For right now, I just want to connect to the remote server with an SWF residing on my local disk. From what I understand, this means that I do not need a security policy file since the SWF is not in another domain. I have also confirmed that the security sandbox property of the file is set to local-trusted, so the SWF should be able to connect to servers and retrieve data from them. Here's the important code from the AS file:

var xmlSocket:XMLSocket = new XMLSocket();
public function MainLogic() {
    xmlSocket.addEventListener(DataEvent.DATA, onDataReceived);
    xmlSocket.connect('XXX.XXX.XXX.XXX', XXXX);
}
public function onDataReceived(event:DataEvent):void {
    helloText.text = 'data received'
}

The server is programmed to send the string 'hello\0' as soon as the connection is made. But if this was happening successfully, then the default text in the dynamic textbox should be replaced with the string 'data received', which is not happening. Is it possible that I still need the policy file even though the SWF file is local?

+1  A: 

Make sure you add in listeners for all potential error events, that will take alot of the guesswork out of debugging. I'd recommend changing up the example from the livedocs to test things out. They set up these events:

xmlSocket.addEventListener(Event.CLOSE, closeHandler);
xmlSocket.addEventListener(Event.CONNECT, connectHandler);
xmlSocket.addEventListener(DataEvent.DATA, dataHandler);
xmlSocket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
xmlSocket.addEventListener(ProgressEvent.PROGRESS, progressHandler);
xmlSocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
grapefrukt
A: 

I'd go with grapefrukt's strategy to see what error you're getting.

My guess is that it's a security error. I think you always need a policy file server when attempting to connect via sockets.

justkevin
A: 

I posted this question with an unregistered account so I can't choose a best answer or comment, but basically adding the event handlers worked perfectly. It did turn out to be a security error, so the policy file may have been the issue. However, I found a much simpler solution is to just modify the settings on the flash player to always allow network access for certain folders or files. I modified the settings with this site: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html

pythonBOI