示例#1
0
文件: TcpServer.cs 项目: L1nY4n/tnt
        private void ProcessClientReceiveSend(TcpClientContext client)
        {
            Byte[] receivedData = ReceiveImpl(client);


            client.Inactive         = false;
            client.InactiveTimeMark = default(DateTime);
            if (receivedData.Length > 0)
            {
                test(receivedData, client);
                IList <Tuple <TcpClientHandlerInfo, Func <Byte[], TcpClientHandlerInfo, Byte[]> > > linkedHandlers =
                    _clientsHandlers.Where(item =>
                {
                    //todo: umv: add special selection for AnyPort and AnyIp
                    return(TcpClientHandlerSelector.Select(item.Item1, client));
                }).ToList();
                foreach (Tuple <TcpClientHandlerInfo, Func <Byte[], TcpClientHandlerInfo, Byte[]> > handler in linkedHandlers)
                {
                    Byte[] dataForSend = handler.Item2(receivedData, handler.Item1);
                    if (dataForSend != null && dataForSend.Length > 0)
                    {
                        SendImpl(client, dataForSend);
                    }
                }
            }
            client.IsProcessing = false;
            OnPropertyChanged();
        }
示例#2
0
文件: TcpServer.cs 项目: L1nY4n/tnt
        public void SendData(TcpClientHandlerInfo clientHandlerInfo, Byte[] data)
        {
            IList <TcpClientContext> selectedClients;

            lock (_tcpClients)
            {
                selectedClients = _tcpClients.Where(item => TcpClientHandlerSelector.Select(clientHandlerInfo, item)).ToList();
            }

            foreach (TcpClientContext client in selectedClients)
            {
                TcpClientContext clientCopy = client;
                Task.Factory.StartNew(() => SendImpl(clientCopy, data));
            }
        }