Ejemplo n.º 1
0
 private void HandleConnect(IAsyncResult ar)
 {
     try
     {
         int clientID = 0;
         while (clientID == 0)
         {
             clientID = rand.Next();
         }
         Console.WriteLine("Local connection: " + clientID);
         TcpClient client = listener.EndAcceptTcpClient(ar);
         client.NoDelay = true;
         networkHandler.ConnectClient(clientID, client, serverEndpoint);
         clients.TryAdd(clientID, client);
     }
     catch
     {
     }
     if (running)
     {
         listener.BeginAcceptTcpClient(HandleConnect, null);
     }
 }