PDA

View Full Version : Problem connecting XMLSocket when swf is hosted


fross
02-15-2007, 01:06 PM
Hi all,

this may not be the usual crossdomain.xml problem you're familiar with, so please read on :)

I have a swf (written in as3) that connects to two servers in different ways - server A it connects to with a URLLoader and gets some static information from. server B it opens an XMLSocket to and gets some streaming data.

When the SWF is served from my local machine (ie a file:// location), both work fine.

When the SWF is served from server A, it connects back to server A with the URLLoader happily, however, the XMLSocket to server B fails. Not explicitly, there is no error, however the XMLSocket never gets an Event.CONNECT happening.

I do have a crossdomain.xml file on a webserver, port 80, on server B. here it is:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

(it's firewalled, so I can do that ;) )

Some things I noticed that are interesting though:
- the crossdomain.xml file on server B is not getting accessed by the flash file. No hits to it are recorded in the webserver's access logs. I've verified I can see the file from a web browser.
- server B is actually getting something from the flash client! I traced it with ethereal, and see a couple of ACKs going back and forth, but I'm not an expert in this sort of thing. After a couple of those messages though, it just stops.
- I set allowScriptAccess to always, in case that affects anything :)

I've not released something to a live environment like this before; I've read the docs but suspect I'm missing something basic here, so any pointers would be very welcome.

Thanks!

fross
02-15-2007, 02:14 PM
I've fixed it!

Just an FYI, for a relatively undocumented "feature"... this is taken from the flash.system.Security.loadPoliceFile API(emphasis mine)

By default, Flash Player looks for policy files in only one location: /crossdomain.xml on the server to which a data-loading request is being made. By default, for an XMLSocket connection attempt, Flash Player looks for /crossdomain.xml on an HTTP server on port 80 in the subdomain to which the XMLSocket connection attempt is being made.

So, if you happen to be running your webserver on www.domain.com, and you're connecting to stream.domain.com port 5000 with your XMLSocket, then by default, it tries to load the crossdomain policy file from domain.com/crossdomain.xml (notice there is no www in it!) - and perhaps you don't have the webserver running on that by default.

the solution is to force the crossdomain policy file location - you can have many of these, so it's not a big issue. but something like:

Security.loadPolicyFile("http://" + myDomain + "/crossdomain.xml");

did the trick for me!

Hope this helps someone, and saves them the 4 hours I wasted :)

najamd
02-22-2007, 01:00 PM
I am developing a chat system using Oregano(http://oregano-server.com).
Using Flash 7, actionscript 2.
Its working fine in Flash player 7, but in browser it doesn't connect. Its using XMLSocket.connect() to connect th server.
Can anyone help me in this regard?

fross
02-22-2007, 01:30 PM
My problem was different - it worked in flash player and the browser (off my harddrive directly), but when the swf was hosted, it didn't work. So I don't think the same solution will work for you.

As far as I know, local SWFs are allowed to access any net resource they can reach. Do you have any browser settings that would stop the SWF from seeing the intended host?

Tink
02-22-2007, 01:32 PM
cross-domain problem?