示例#1
0
        public TelnetService(ITCPServer tcpServer, ITelnetCommand[] customCommands)
        {
            m_TCPServer        = tcpServer;
            m_Clients          = new ConcurrentDictionary <string, ConnectedClient>();
            m_ReceivedCommands = new ConcurrentQueue <ReceivedCommandItem>();
            m_Settings         = new TelnetServiceSettings();

            buildCommandsCatalog(customCommands ?? new ITelnetCommand[0]);
        }
示例#2
0
        public bool Start(TelnetServiceSettings settings)
        {
            if (m_IsRunning)
            {
                return(true);
            }

            m_Settings = settings.Clone();

            int    _portNo    = m_Settings.PortNumber;
            string _ipAddress = null;

            if (!m_Settings.ListenAllAdapters && !String.IsNullOrEmpty(m_Settings.LocalIPAddress))
            {
                _ipAddress = m_Settings.LocalIPAddress;
            }

            IPEndPoint _endPoint = new IPEndPoint(!String.IsNullOrEmpty(_ipAddress) ? IPAddress.Parse(_ipAddress) : IPAddress.Any, _portNo);

            clearClientsAndReceivedCommands();

            m_TCPServer.ClientConnected    += m_TCPServer_ClientConnected;
            m_TCPServer.ClientDisconnected += m_TCPServer_ClientDisconnected;
            m_TCPServer.DataReceived       += m_TCPServer_DataReceived;

            try
            {
                m_TCPServer.StartListening(_endPoint);
                m_IsRunning = true;

                m_thrCommandProcessor      = new Thread(commandProcessorThread);
                m_thrCommandProcessor.Name = "TelnetCommandProcessor";
                m_thrCommandProcessor.Start();
            }
            catch (Exception ex)
            {
                //log.Error("TelnetService could not be started.", ex);
                Stop();
            }

            return(true);
        }