- Home /
Security Policy works with WWW but not with PrefetchSocketPolicy on web port?
I cannot seem to get the security policy to work to allow me to open a connection to SFS.
I put crossdomain.xml into my web root, and I try to prefetch it on port 80, but it basically locks up for a long time (even the timeout doesn't seem to work--it is in milliseconds, right?), before returning false.
However, if I just try to open a WWW connection, it automatically grabs the policy, and continues happily. This leads me to believe I've got it set up correctly.
Here's a sample:
WWW www = new WWW( "http://" + serverIP + "/robots.txt" ); // can see in web server log the request for // crossdomain.xml, then robots.txt
if( !Security.PrefetchSocketPolicy( serverIP, 80, 500 ) ) { // this always fails, and it takes a long time to fail // (more than 500ms), and there are no requests in the web server logs Debug.LogError( "Failed to retrieve security policy" ); }
So why would it work for the one, but not the other? Why would there be no access request? Or how can I put a listener on port 843 on a Linux box so I don't need to use the web server?
Answer by cncguy · Apr 29, 2011 at 04:32 AM
My understanding is that for connections to sockets you must have a socketPolicyServer on your server listening for connections. If it listens on port 843 then you don't need to use PrefetchSocketPolicy as when you try to make a socket connection unity automatically checks for a policy returned from port 843 of the server you are trying to connect to.
Unity ships with a default socketPolicyServer written in C#. Unfortunately that won't help you with linux (actually I am looking for a linux one too) although linux must have a command ine tool to listen on a port and return an xml file on a received connection. I have used unity supplied socket policy server successfully on a windows server so can confirm that this is what you need. The xml policy file on the root of your server is not checked when a socket connection is requested. That is for HTTP requests and the like.
see:
http://unity3d.com/support/documentation/Manual/Security%20Sandbox.html
I read all the docs, and every post I could find, before asking here; it just was not very clear to me (and now it seems that all the other posts may have confused matters more). But the short answer is "they're not the same thing so you need the Linux server", and I thank you for that.
PrefetchSocketPolicy() still doesn't do ANYTHING but failing. I've set up a crossdomain-server on port 843 which is delivering the privacy rules.
Also neiter TcpClient nor UdpClient works. I see the privacy-request in node.js though, but Unity keeps complaining with a freaking vague message:
"SecurityException: Unable to connect, as no valid crossdomain policy was found"
var net = require("net");
net.createServer(
function(socket)
{
console.log("got request...");
socket.write("<?xml version=\"1.0\"?>\n");
socket.write("<cross-domain-policy>\n");
socket.write("<allow-access-from domain=\"*\" to-ports=\"*\"/>\n");
socket.write("</cross-domain-policy>\n");
socket.end();
}
).listen(843);
Edit: I realized that my setup works, but only as native build on Windows. Neither in Debug IDE nor Web Player. :(
I just consider buying Unity 5 because of the ability to make a multiplayer game for my Website...
I got Unity 5 and having a similar problem. In my case the game does a WWW call to a php script to receive the server IP, then connects to the server using sockets (Network class). I'm still getting these very long freezes, sometimes are shorter than others (which is weird)... anyways if you come across a reason for this issue please post
Your answer
Follow this Question
Related Questions
How to serve security policy on linux system? 2 Answers
Error with Facebook's crossdomain file? 0 Answers
No valid crossdomain policy available to allow access 1 Answer
crossdomain issue 1 Answer