private void CloseTcpClient(SenderContext tcpContext) { tcpContext.TcpReceiver.Stop(); tcpContext.TcpSender.Stop(); tcpContext.TcpClient.Close(); tcpSenders.Remove(tcpContext); }
private void AddClient(TcpClient client) { TcpReceiver tcpReceiver = new TcpReceiver(client); tcpReceiver.OnData += OnDataReceivedFromTcp; var tcpContext = new SenderContext { TcpClient = client, TcpSender = new TcpSender(client), TcpReceiver = tcpReceiver }; tcpContext.TcpSender.Closed += CloseClient; tcpContext.TcpReceiver.Closed += CloseClient; tcpSenders.Add(tcpContext); if (TcpSettings.Mode == TcpServerSettings.TcpServerMode.Write) { tcpContext.TcpSenderTask = tcpContext.TcpSender.Start(); } else { tcpContext.TcpReceiverTask = tcpContext.TcpReceiver.Start(); } }
private void CloseClient(object sender, EventArgs e) { SenderContext tcpContext = tcpSenders.FirstOrDefault(c => c.TcpSender == sender); if (tcpContext != null) { CloseTcpClient(tcpContext); } }