0
我做了一個簡單的套接字serer腳本和客戶端腳本。套接字服務器連接錯誤
如果我在同一個項目中運行這兩個腳本沒有問題,但如果我從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();
}
}
}
什麼是錯誤和/或問題?!? – tzerb
這是由網絡播放器或桌面運行嗎? –