Esempio n. 1
0
        //public async void AcceptClientsAsync()
        //{
        //    try
        //    {
        //        while (this.Active)
        //        {
        //            TcpChatClient newClient = new TcpChatClient(await this.AcceptTcpClientAsync(), this);
        //            this.clients.Add(newClient);
        //            // this.notifyEveryone += newClient.SendNotification;
        //            newClient.ReceiveMessagesAsync();
        //        }
        //    }

        //    catch (Exception e)
        //    {
        //        Console.WriteLine(e.Message);
        //    }
        //}

        public void RemoveConnection(Guid id)
        {
            TcpChatClient client = clients.FirstOrDefault(c => c.id == id);

            if (client != null)
            {
                clients.Remove(client);
            }
        }
Esempio n. 2
0
 public void Listen()
 {
     try
     {
         while (true)
         {
             TcpChatClient newClient = new TcpChatClient(this.AcceptTcpClient(), this);
             this.AddConnection(newClient);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         // Disconnect();
     }
 }
Esempio n. 3
0
 public void AddConnection(TcpChatClient newClient)
 {
     clients.Add(newClient);
 }