Tuesday, September 04, 2012

UniWeb, WWW and crossdomain.xml explained.

I get many confused emails from people trying to get UniWeb to work in the Unity WebPlayer. It works, but you have to set things up correctly, as described in the manual. I'll explain it again here, maybe it will reduce the influx of support emails!

Situation #1.
You want to use the builtin WWW class to fetch stuff from a HTTP server.

In this case, you MUST have a crossdomain.xml file that is hosted by that SAME HTTP server,

This will allow, and ONLY allow Unity's builtin WWW class to work. It has no effect on the usage of .NET sockets within Unity.

This particular setup will NEVER help you get .NET sockets (and by
extension UniWeb) working within Unity WebPlayer.

Situation #2.
You want to use UniWeb to fetch stuff from a HTTP server.

In this case, you MUST have a server process running on a port on the SAME host, which follows the behaviour specified in the manual.

This will allow .NET sockets (and therefore UniWeb) to work within a Unity WebPlayer. The Security.PrefetchSocketPolicy MUST be called before .NET sockets will successfully connect to a host on ANY port.

Particularly note this section from the manual:
Specifically the server expects to receive a zero-terminated string
that contains . It only sends to the client the socket policy xml document when this string (and exactly this string) has been received. Further, it is required that the xml header and xml body are sent with a single socket write.

Also note:
Note: Whilst the crossdomain.xml and socket policy files are both xml
documents and are broadly similar, the way that these documents are served are very different. Crossdomain.xml (which applied to http requests) is fetched using http on port 80, where-as the socket policy is fetched from port 843 using a trivial server that implements the <policy-file-request/>. You cannot use an http server to issue the socket policy file, nor set up a server that simply sends the socket policy file in response to a socket connection on port 843. Note also that each server you connect to requires its own socket policy server.


Anonymous said...

I don't understand. Can you please explain in smaller words. Thanks

Simon Wittber said...

LOL just for you Paul, I'll get my nephew to translate! ;-)

Thet Naing Swe said...

I've setup the socket policy server on port 1201 and I can successfully call Security.PrefetchSocketPolicy ("", 1201, 50000) function to prefetch as I am using different port rather than 843.

After that, I am trying to call using UniWeb and it still returns System.Security.SecurityException: Unable to connect, as no valid crossdomain policy was found

error. Can you please point me my missing point?

Thanks alot

Simon Wittber said...

I would start by verifying that your security policy server is actually receiving a request when you call Security.Prefetch, then I would verify that your crossdomain.xml file is valid.

Thet Naing Swe said...

Yes, you can verify that the crossdomain.xml here

and you can call Security.PrefetchSocketPolicy ("", 1201, 50000) which returns true... which seems to me that the socket policy server is actually receivine a request.

Popular Posts