Example #1
0
        public async void ServerStarted(IListener listener, int port)
        {
            var intervall = Intervall.Get();

            while (true)
            {
                var result = await _detectedManager.ReceiveResult(listener, port);

                if (!result.IsSuccess)
                {
                    foreach (var error in result.Messages)
                    {
                        Console.WriteLine($"Client Error=>:{error.Key} / Desc:{error.Message} ");
                    }
                    continue;
                }


                var sb = new StringBuilder();
                foreach (var item in result.Data.DetectionList)
                {
                    sb.Append($" {item}");
                }
                var getBytes = Encoding.ASCII.GetBytes(sb.ToString());

                var getClient = _clientEp.GetClientByUserId(result.Data.UserId);
                if (getClient != null)
                {
                    await _client.SendData(getClient.IpEndPoint, getBytes);

                    intervall.SetOutInputFrequency();
                    _clientEp.RemoveClientByUserId(result.Data.UserId);
                }
            }
        }
Example #2
0
        public async void ServerStarted(IListener listener)
        {
            Intervall intervall = Intervall.Get();

            Thread consoleEffect = new Thread(new ParameterizedThreadStart(ConsoleEffect.Effect));

            consoleEffect.Start(listener.Message().Length);

            while (true)
            {
                Console.WriteLine();
                Console.Write($"{ listener.Message()} =>");

                var result = await listener.Listen();

                var stream = ResultParse <Stream> .jsonDeserialize(result.ReceiveData);

                var checkResult = _detectedManager.ResultValidator(stream);

                if (!checkResult.IsSuccess)
                {
                    foreach (var error in checkResult.Messages)
                    {
                        Console.WriteLine($"Server Error=>{error.Key} / Desc:{error.Message} ");
                    }
                    continue;
                }

                _clientEp.AddClient(stream.UserId, result.IPEndPoint);

                StatisticsModel statistics = new StatisticsModel
                {
                    Stream     = stream,
                    IPEndPoint = result.IPEndPoint
                };

                intervall.SetIntervall(statistics);

                await _detectedManager.SendResult(stream);
            }
        }