September 16, 2005 1:07 PM   Subscribe

Anyone know how to use an XMLSocket in flash (using actionscript)

I've been trying for days to get XMLSocket.connect to work. And it just
won't. It always returns false. The code I'm using is:

var net:XMLSocket = new XMLScoket();

net.onConnect = function(success:Boolean){
XMLResult.text = "connection failed on onconnect";
XMLResult.text = "succeeded!";


var b:Boolean = net.connect("localhost",4482);
XMLResult.text = "----failed to connect";

XMLResult.text = "---connected";


b is *always* false, no matter what I try. I put the swf file on the
hard drive, I've had it downloaded from localhost over HTTP, I put up a
polcy file, My windows firewall is turned off. I've tried everything,
and it won't even get to the 'onConnect' part! WTF is going on?

The crazy thing is, if I call the following code"xmlsocket://localhost:4482");

The Flash player makes a network connection, sends the correct XML, and
downloads the result just fine! But when I call XMLsocket.connect() it
just returns false and won't even try to connect to my server!

The flash movie has no problem doing an XML.load() from the same server
(using the HTTP protocol).

This is driving me crazy. I've been going over the security and policy
stuff like crazy, and I still have no idea what's going on. It's driving me totaly nuts.

(I hate flash)
posted by delmoi to Computers & Internet (5 answers total)
Out of curiosity, have you tried adding a crossdomain.xml file in the root path of the server hosting the downloaded XML? The file should contain the following data for testing purposes:
	<allow-access-from domain="*"/>
I know relatively little about Flash itself, but my company makes extensive use of it, and the lack of a crossdomain.xml is one of the most common causes for Flash security issues. That, and missing allowDomain() calls in externally-loaded SWFs.
posted by Danelope at 9:14 PM on September 16, 2005

Response by poster: Yeah, I have a crossdomain.xml file, and I'm not using any external SWF files :(
posted by delmoi at 9:16 PM on September 16, 2005

Best answer: Also, uhh, you spelled "socket" wrong at the end of that first line of code. And I know the Flash IDE is useless as far as debugging goes, and doesn't acknowledge things like undefined variables or classes...
posted by Danelope at 9:20 PM on September 16, 2005

Response by poster: Danelope, you're right.

Jesus fucking christ.

Good thing I only live a block away from work... let me check that.
posted by delmoi at 9:31 PM on September 16, 2005

Response by poster: Oh. My. God.

That was it. And it dosn't help that actionscript treats 'null' as 'false'.

God damn. Two fucking days I've been beating my head against the wall trying to figure out what was wrong. I did the following:

*Add a authentification system to my XMLSocket server
*read the same damn documentation over and over again
*Add an HTTP authentification system, so I could see if that would help
*Post on newgroups
*Download the flash 8 trial (which just came out this month)
*add the the ability to send the swf file itself from the HTTP server

Not to mention tons of tweaking in each one of those steps And nothing worked.

Thanks a lot :P
posted by delmoi at 9:49 PM on September 16, 2005

« Older Any recommendations for an LCD monitor test?   |   Tips for October visit to LA and SF? Newer »
This thread is closed to new comments.