public void StartServer(string ip, int port, int maxClient)
        {
            semaphore    = new Semaphore(maxClient, maxClient);
            pool         = new ClientPeerPool(maxClient);
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            for (int i = 0; i < maxClient; i++)
            {
                ClientPeer client = new ClientPeer();
                client.ReceiveCompleted += OnRecieve;
                pool.Push(client);
            }

            serverSocket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
            serverSocket.Listen(maxClient);

            app.Init();//初始化app
            Console.WriteLine("服务器启动成功");
            StartAccept(null);
        }
 private void StartReceive(ClientPeer client)
 {
     client.clientSocket.BeginReceive(client.receiveBuffer, 0, ClientPeer.bufferSize, SocketFlags.None, ReceiveCallback, client);
 }
 /// <summary>
 /// 客户端接收数据后的回调
 /// </summary>
 /// <param name="client"></param>
 /// <param name="msg"></param>
 private void OnRecieve(ClientPeer client, NetMsg msg)
 {
     app.ReceiveMessage(client, msg);
 }
 /// <summary>
 /// 归还一个客户端对象
 /// </summary>
 /// <param name="client"></param>
 public void Push(ClientPeer client)
 {
     pool.Enqueue(client);
 }