Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sockets 套接字服务器连接错误_Sockets_Connection_Unity3d_Crossdomain.xml - Fatal编程技术网

Sockets 套接字服务器连接错误

Sockets 套接字服务器连接错误,sockets,connection,unity3d,crossdomain.xml,Sockets,Connection,Unity3d,Crossdomain.xml,我制作了一个简单的socketserer脚本和一个客户端脚本 如果我在同一个项目中运行两个脚本,没有问题,但是如果我从Unity3D游戏引擎运行客户端脚本,则没有连接,并且控制台说我需要跨域策略 using System; using System.Collections.Generic; using System.Linq; using System.Text; //using System.Threading.Tasks; using System.Net; using System.Net

我制作了一个简单的socketserer脚本和一个客户端脚本

如果我在同一个项目中运行两个脚本,没有问题,但是如果我从Unity3D游戏引擎运行客户端脚本,则没有连接,并且控制台说我需要跨域策略

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();
        }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
//使用System.Threading.Tasks;
Net系统;
使用System.Net.Sockets;
命名空间SocketServer
{
班级计划
{
静态字节[]缓冲区{get;set;}
静态插座;
静态void Main(字符串[]参数)
{
sck=新套接字(AddressFamily.InterNetwork、SocketType.Stream、ProtocolType.Tcp);
sck.Bind(新的IPEndPoint(05111));
听(100);
接受套接字=sck.Accept();
Buffer=新字节[accepted.SendBufferSize];
int bytesRead=accepted.Receive(缓冲区);
字节[]格式化=新字节[字节读取];
for(int i=0;i
如果您的unity build设置为web player,则会出现跨域策略错误。另一方面,桌面/独立构建设置应在没有跨域策略问题的情况下工作。您可以使用Unity standalone和Raknet(用于套接字)实现套接字实现。我已经实现了它,可以像socket一样进行通信。这是文档链接

有什么错误和/或问题?!?这是由web播放器运行还是由桌面运行?