How Can I Disable Cross-Domain Policy Request?

641 views Asked by At

I started to work on unity3d. I just wanna send/receive data between Unity3D and Raspberry Pi. I used socket programming for that. But when I try to connect my Raspberry Pi, Unity send me error message that "Unable to connect as no valid cross-domain policy was found". Why cross-domain policy is required. I just wanna send or receive a data between my pc and raspberry. Can I disable cross-domain policy request or how can I solve this problem.

public static void StartClient() {
    byte[] bytes = new byte[1024];
    int remotePort = xxxx; // My raspberry port
    try {
        IPHostEntry ipHostInfo = Dns.GetHostEntry("xxx.xxx.xxx.xxx"); //-->> my raspberry IP
        IPAddress ipAddress = ipHostInfo.AddressList[0];
        IPEndPoint remoteEP = new IPEndPoint(ipAddress,remotePort);

        Socket mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );

        try {
            mySocket.Connect(remoteEP);

            print("Socket connected to" + mySocket.RemoteEndPoint.ToString());

            byte[] msg = Encoding.ASCII.GetBytes("This is a test<EOF>");

            int bytesSent = mySocket.Send(msg);

            int bytesRec = mySocket.Receive(bytes);
            print("Echoed test = " + Encoding.ASCII.GetString(bytes,0,bytesRec));

            mySocket.Shutdown(SocketShutdown.Both);
            mySocket.Close();

            }
        catch (ArgumentNullException ane) {
            print("ArgumentNullException : " + ane.ToString());
        } 
        catch (SocketException se) {
            print("SocketException : " + se.ToString());
        }
        catch (Exception e) {
            print("Unexpected exception : " + e.ToString());
        }

    }
    catch (Exception e) {
        Console.WriteLine( e.ToString());
    }
}
1

There are 1 answers

4
joreldraw On

You can't disable this. Is a seccurity protectión on WWW request and Sockets. You need to make on your pc an authorization for this connections. The deafult port for this seccurity cheching is 843.

You can use the included example program from Unity existing on the installation folder/Data/Tools/SocketPolicyServer or can make your own service running listening to this port or including an xml file if you have your Pc how a webserver something like this:

<?xml version="1.0"?>
<cross-domain-policy>
   <allow-access-from domain="*" to-ports="1200-1220"/> 
</cross-domain-policy>"