//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); } }
public void Listen() { try { while (true) { TcpChatClient newClient = new TcpChatClient(this.AcceptTcpClient(), this); this.AddConnection(newClient); } } catch (Exception ex) { Console.WriteLine(ex.Message); // Disconnect(); } }
public void AddConnection(TcpChatClient newClient) { clients.Add(newClient); }