Exemple #1
0
        public void Listen()
        {
            _running     = true;
            _tcpListener = new TcpListener(IPAddress.Loopback, _port);
            _tcpListener.Start();

            while (_running)
            {
                TcpClient newClient = null;
                try
                {
                    newClient = _tcpListener.AcceptTcpClient();
                    var stream         = newClient.GetStream();
                    var sessionMessage = new SessionMessage();
                    sessionMessage.MergeDelimitedFrom(stream);
                    var sessionId = sessionMessage.SessionStart.SessionId;
                    _channelDictionary.AddOrUpdate(sessionId, new LocalChannel(newClient), (k, v) => v);
                    _newChannelEvent.Set();
                }
                catch (Exception e)
                {
                    newClient?.Dispose();

                    if (_running)
                    {
                        LogService.Log("Error on accepting new channel session", e);
                        throw;
                    }
                }
            }
            LogService.Log("XXX: Channel Server exiting...");
        }