I am trying to serve a crossdomain policy file from a Java server to the Unity webplayer. When the webplayer connects to the server, the console (server-side) shows: “ServingPolicyFile CONNECTION MADE”, but the webplayer throws an exception:
SecurityException: Unable to connect, as no valid crossdomain policy was found
System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error, Boolean requireSocketPolicyFile)
System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error)
System.Net.Sockets.Socket.Connect (System.Net.IPAddress[] addresses, Int32 port)
System.Net.Sockets.Socket.Connect (System.String host, Int32 port)
Here is the server code (Java)
public class ServingPolicyFile {
final private static int PORT = 843;
final private static String POLICY_FILE_FORMAT = "<?xml version='1.0'?><cross-domain-policy><allow-access-from domain=\"%s\" to-ports=\"%s\"/></cross-domain-policy>\0";
final private ExecutorService _executor = Executors.newSingleThreadExecutor();
final private ServerSocket _servingSocket;
final private String _policyFile;
public ServingPolicyFile(String policyFile) throws IOException {
_servingSocket = new ServerSocket(PORT);
_policyFile = policyFile;
}
public ServingPolicyFile(int port) throws IOException {
this(String.format(POLICY_FILE_FORMAT, "*", port));
}
public void close() throws IOException {
_executor.shutdownNow();
_servingSocket.close();
}
public void start() {
_executor.submit(() -> {
while (true) {
try (Socket socket = _servingSocket.accept(); PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) {
System.out.println("ServingPolicyFile CONNECTION MADE");
out.println(_policyFile);
}
}
});
}
}
Does anyone know what the issue might be?
I tried serving the EXACT policy file (copy & pasted) from the unity docs, but that didn’t work either.