internal void Connected() { _transmission = new TcpTransmission(_tcpClient, _validator.Interpreter, Logger.GetChild(string.Empty, typeof(TcpTransmission))); _transmission.Disconnected += ConnectionClosed; _transmission.ExceptionOccured += OnTransmissionException; _transmission.Received += MessageReceived; _transmission.StartReading(); // Configure TCP keep alive if (Config.MonitoringIntervalMs > 0) { _transmission.ConfigureKeepAlive(Config.MonitoringIntervalMs, Config.MonitoringTimeoutMs); } }
private void ClientConnected(IAsyncResult ar) { TcpClient client; try { client = _tcpListener.EndAcceptTcpClient(ar); } catch (Exception) { return; } // Create new transmission and try to assign var tcpTransmission = new TcpTransmission(client, _protocolInterpreter, _logger.GetChild(string.Empty, typeof(TcpTransmission))); lock (_listeners) { if (_listeners.Count == 1 && !_listeners[0].ValidateBeforeAssignment) { // If we have only one listenere we can assign directly var listener = _listeners[0]; RemoveListener(listener); listener.AssignConnection(tcpTransmission); } else { // Wait for the first message to assign the connection tcpTransmission.Disconnected += TransmissionDisconnected; tcpTransmission.Received += InitialReceive; } // If we have listners without a connection keep accepting clients if (_listeners.Count > 0) { _tcpListener.BeginAcceptTcpClient(ClientConnected, null); } } tcpTransmission.StartReading(); }