Exemplo n.º 1
0
 public Server(int cnt, string IP)
 {
     CountClient = cnt;
     Players     = new PlayerServer[cnt];
     for (int i = 0; i < cnt; i++)
     {
         Players[i] = new PlayerServer();
     }
     Listner = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     Listner.Bind(new IPEndPoint(IPAddress.Parse(IP), 11000));
     Listner.Listen(20);
 }
Exemplo n.º 2
0
        public async Task <int> NextClient()
        {
            var sock = await Listen();

            int i = 0;

            while (i < CountClient && (Players[i].IsOnline || !Players[i].IsRemote))
            {
                ++i;
            }
            if (i == CountClient)
            {
                return(-1);
            }
            Players[i] = new PlayerServer();
            Players[i].SetOnline(sock);
            return(i);
        }