public TcpServer(string ip, int port, PackType type = PackType.All, int thread = 8) { tCount = thread; packType = type; if (tCount > 0) { linkBuff = new LinkThread <T> [tCount]; for (int i = 0; i < tCount; i++) { linkBuff[i] = new LinkThread <T>(SingleCount); } } else { tCount = 1; linkBuff = new LinkThread <T> [1]; linkBuff[0] = new LinkThread <T>(SingleCount); } soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); soc.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); //端点 endPoint = new IPEndPoint(IPAddress.Parse(ip), port); //绑定 try { soc.Bind(endPoint); } catch (Exception ex) { UnityEngine.Debug.Log(ex.StackTrace); } soc.Listen(0); Instance = this; }
public void Run(int threadCount = 8, int threadbuff = 2048) { tCount = threadCount; if (tCount > 0) { linkBuff = new LinkThread <T> [threadCount]; for (int i = 0; i < threadCount; i++) { linkBuff[i] = new LinkThread <T>(threadbuff); } } else { tCount = 1; linkBuff = new LinkThread <T> [1]; linkBuff[0] = new LinkThread <T>(); } Start(); }