예제 #1
0
        private void ProcessClient(NetworkClient networkClient)
        {
            if (networkClient.IsOnline)
            {
                return;
            }

            var clientOnServer =
                ClientsOnServer.FirstOrDefault(
                    x => x.TcpClient.Client.RemoteEndPoint.Equals(networkClient.Adress));

            RemoveClient(clientOnServer);
        }
예제 #2
0
        private void ProcessTextMessage(NetworkMessage message, TcpClient client)
        {
            var clientOnServer =
                ClientsOnServer.FirstOrDefault(
                    x => Equals(x.TcpClient.Client.RemoteEndPoint, message.FromPoint));

            if (clientOnServer != null)
            {
                clientOnServer.LastActivityTime = DateTime.Now;

                SaveMessageToLogFile(message, clientOnServer.Name);
            }

            var isDelivered = SendMessage(message);

            //отправка информации о состоянии сообщения
            client.PutDataToStream(new NetworkMessageState(isDelivered));
        }
예제 #3
0
        private bool SendMessage(NetworkMessage message)
        {
            try
            {
                var netClient =
                    ClientsOnServer.FirstOrDefault(x => Equals(x.TcpClient.Client.RemoteEndPoint, message.ToPoint));

                if (netClient != null)
                {
                    netClient.TcpClient.PutDataToStream(message);
                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }