// Called when a message is received from a client protected void Client_MessageReceived(Client Sender, Message Msg) { if (BufferMessages) // Store message in message queue Messages.Add(new ClientMessagePair(Sender, Msg)); else // Fire message received event ClientMessageReceived(this, Sender, Msg); }
public ClientMessagePair(Client Client, Message Message) { this.Client = Client; this.Message = Message; }
protected void Client_Disconnect(Client Sender, DisconnectMessage Msg) { // Detach event handlers Sender.Disconnect -= Client_Disconnect; Sender.MessageReceived -= Client_MessageReceived; Sender.Dispose(); lock (Clients) // Thread safe Clients.Remove(Sender); // Fire disconnection event ClientDisconnect(this, Sender, Msg); }