I am using Apache server to host my Unity game. I also have a php file on the server to write game data to a database.
I have a crossdomain.xml file at the root of the server which contains the following:
<allow-access-from domain="*" to-ports="*" />
I am also running 'sockpol --all' on the server.
When I call 'ret = Security.PrefetchSocketPolicy("server ip", 843);' it returns false and when the hs_post = WWW(gamedata_url) call is made it returns the error 'Rejected because no crossdomain.xml policy file was found'.
I know the code is correct because when I run it using a local server it writes to the database correctly. It is only when I place the php file on the server and try to access it remotely that it doesn't work. I have spent many hours trying to resolve this issue without any success. Any help would be greatly appreciated.
My crossdomain file never got read properly until I opened it and saved it with a text editor (vi) on the server.
It wasn't working at first and I found a thread here about people having issues due to the character set used by their text editors. I opened with vi, saved, exited, and it worked.
Small chance it works for you, but thought I'd mention it....
Answer by Graham-Dunnett
Jul 19, 2011 at 06:52 PM
There are a few comments to make.
Firstly, the sockpol application is there to support clients that need to make access to your server using sockets. If you are only using the WWW class then you should not need this application running, and the Unity webplayer will not connect to your server over port 843.
The Security.PrefetchSocketPolicy is not needed if you are using the WWW class (only).
The first time you make a WWW request to a URL different from where the unity3d file comes from Unity will try to read the crossdomain.xml file from your server. You may care to examine your server logs to determine if this file has been requested and returned. It's possible your server is not configured to serve XML files. (You could also try to fetch the crossdomain.xml directly using a web browser and checking that the server delivers it. Or try using curl to fetch it.)
As jahroy says, the crossdomain.xml must be a pure ascii file, as per the documentation.
Answer by user-12176 (google)
Jul 19, 2011 at 07:34 PM
Thanks for the swift replies. I have already tried that Jahroy, both UTF-8 and ASCII but no luck. Your advice should be helpful in narrowing down the problem Graham, no that I know sockpol and Security.PrefetchSocketPolicy are not relevant for what I'm trying to achieve. I have previously tried fetching the xml file directly through the browser and that works no problem. I will look through the log files to see if that will shed any light on the problem. I will need to look into whether or not Apache can serve xml files. Perhaps you can suggest a Windows server which will definitely serve the xml file and therefore work with Unity webplayer out of the box? Thanks again guys, your feedback is much appreciated...,Thanks Jahroy and Graham, I appreciate your swift replies. I have tried encoding the xml file in both UTF-8 and ANSI and neither made any difference unfortunately. It is good to know that 'Security.PrefetchSocketPolicy' is not need for what I'm trying to achieve Graham, could help me narrow down the problem. I have also tried checking if it is delivered directly and it is...I will need to look into configuring Apache to serve XML files. Perhaps you could suggest another Windows server which will definitely work in this way?... Thanks again guys...
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
5 People are following this question.
yield return WWW.text not downloading???
WWW doesn't work on localhost eventhough crossdomain.xml exists
WWW does not work on localhost
loading from disk, saving to database
Best way to protect www post to a php file ?