Search Unity

Trying to do Client-server TCP connection in web player...

Discussion in 'Multiplayer' started by Flynn, Jan 24, 2012.

  1. Flynn

    Flynn

    Joined:
    May 24, 2009
    Posts:
    311
    Hello :) Long story short.. I am working on a Client-Server networking solution. I have a dedicated server with the proper ports open and listening for connections. My Unity project connects to that server and its port, and begins sending data.

    Works fine! Except....

    When I try to run it in the webplayer.... I get this:


    Code (csharp):
    1. SecurityException: Unable to connect, as no valid crossdomain policy was found
    2. System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32 error, Boolean requireSocketPolicyFile)
    3. System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy)
    4. System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP)
    5. System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point)

    Here is the code for my client:


    Code (csharp):
    1. public class ClientTest : MonoBehaviour {
    2.     BinaryWriter so;
    3.     // Use this for initialization
    4.     void Start () {
    5.         TcpClient client = new TcpClient();
    6.  
    7.         IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("-Censored-IP-"), 5en50r3d p0r1);
    8.  
    9.         client.Connect(serverEndPoint);
    10.  
    11.         NetworkStream clientStream = client.GetStream();
    12.        
    13.         while (!clientStream.CanRead || !clientStream.CanWrite)
    14.         {
    15.             Debug.Log("Spinning until can write");
    16.         }
    17.         so = new BinaryWriter(clientStream);
    18.    
    19.         so.Write("Blah blah blah");
    20.         so.Flush();
    21.    
    22.    
    23.     }
    24. }
    25.  
    How might I configure my code to resolve these cross-domain issues, and enable web-player support for my networking?
     
    Last edited: Jan 24, 2012
  2. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
  3. Flynn

    Flynn

    Joined:
    May 24, 2009
    Posts:
    311
    Thank you thank you THANKYOU Fholm! Works like a charm!
     
  4. fholm

    fholm

    Joined:
    Aug 20, 2011
    Posts:
    2,052
    No problem :)