private void HandleReceivedData(byte[] buffer) { MethodInvoker method = null; TransferPackage package = new TransferPackage(buffer); switch (package.TransferAction) { case TransferAction.ListClient: method = () => { ListClientModel listModel = package.Data as ListClientModel; lstClients.Items.Clear(); lstClients.Items.AddRange(listModel.Clients); }; break; case TransferAction.SendMessage: method = () => { MessageModel messageModel = package.Data as MessageModel; lstMessages.Items.Add(messageModel.ClientName + ": " + messageModel.Message); }; break; } if (method != null) { Invoke(method); } }
private void TimerCallbackAction(object state) { foreach (var client in server.Clients) { ListClientModel listClientModel = new ListClientModel { Clients = server.Clients.Where(x => x.Id != client.Id).Select(x => new ClientModel { Id = x.Id, Name = x.Name }).ToArray() }; TransferPackage package = new TransferPackage(TransferAction.ListClient, listClientModel); client.Socket.Send(package.ToByteArray()); } }