public async Task Start() { try { listener = new TcpListener(IPAddress.Parse(_configProvider.ipAddress), _configProvider.port); listener.Start(); _outputLog.LogMessage("Waiting for clients..."); while (true) { TcpClient client = await listener.AcceptTcpClientAsync(); TCPReciever reciever = new TCPReciever(client, _outputLog); //TODO create objects with object factory clientsCount++; _outputLog.LogMessage("New client connected"); var task = Task.Factory.StartNew(() => reciever.ProcessMessage()); if (_configProvider.maxClientCont > 0 && clientsCount >= _configProvider.maxClientCont) { break; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { if (listener != null) { listener.Stop(); } } }
public async Task ProcessMessage(string message) { try { await Send(message); var responceMessage = await Read(); _output.LogMessage($"Sent '{message}' response '{responceMessage}'"); } catch (Exception ex) { _output.LogMessage(ex.Message); } }
public async Task ProcessMessage() { try { while (true) { var reseivedMessage = await Read(); await Send("OK"); _output.LogMessage(reseivedMessage); } } catch (Exception ex) { _output.LogMessage(ex.Message); } finally { Dispose(); } }
public void Start() { _outputLog.LogMessage($"Connecting to Monitor"); _metricPovider.metricUpdated += SendMessage; }