コード例 #1
0
 private void CloseTcpClient(SenderContext tcpContext)
 {
     tcpContext.TcpReceiver.Stop();
     tcpContext.TcpSender.Stop();
     tcpContext.TcpClient.Close();
     tcpSenders.Remove(tcpContext);
 }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        private void CloseClient(object sender, EventArgs e)
        {
            SenderContext tcpContext = tcpSenders.FirstOrDefault(c => c.TcpSender == sender);

            if (tcpContext != null)
            {
                CloseTcpClient(tcpContext);
            }
        }