0

i have made a simple socket serer script and a client script.

if i run both scripts in the same project there is no problem but if i run the client script from Unity3D game engine there is no connection and the console said i need a Crossdomain policy.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
namespace SocketServer
{
    class Program
    {
        static byte[] Buffer { get; set; }
        static Socket sck;

        static void Main(string[] args)
        {

            sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            sck.Bind(new IPEndPoint(0, 5111));
            sck.Listen(100);


            Socket accepted = sck.Accept();
            Buffer = new Byte[accepted.SendBufferSize];
            int bytesRead = accepted.Receive(Buffer);
            byte[] formatted = new byte[bytesRead];
            for (int i = 0; i < bytesRead; i++)
            {
                formatted[i] = Buffer[i];
            }

            string strData = Encoding.ASCII.GetString(formatted);
            Console.Write(strData + "\r\n");
            Console.Read();
            sck.Close();
            accepted.Close();
        }
    }
}
Alexis Pigeon
  • 7,423
  • 11
  • 39
  • 44

1 Answers1

1

If your unity build setting is web player, then you will get cross domain policy error. In the other hand, the Desktop/Standalone build setting should work without cross domain policy problem. You are able to implement the socket implementation with Unity standalone and Raknet (for the socket). I have already implemented it and can do a communication like socket does. Here is the documentation link http://www.jenkinssoftware.com/raknet/manual/detailedimplementation.html

Community
  • 1
  • 1