public void StartInfoChannel() { server = MyTCPServer.Instance; //setting it yet again to false in case disconnect is pressed, and then connect again stop = false; server.EstablishConnection(); }
private void m_TCPServer_ClientDisconnected(ITCPServer server, ClientInfo client) { ConnectedClient _connectedClient; if (m_Clients.TryRemove(client.ClientID, out _connectedClient)) { // } }
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]); }
private void m_TCPServer_ClientConnected(ITCPServer server, ClientInfo client) { ConnectedClient _connectedClient = new ConnectedClient(); _connectedClient.Client = client; _connectedClient.CommandBuffer = null; _connectedClient.TextEncoder = Encoding.GetEncoding(m_Settings.Charset); _connectedClient.IsLoginRequired = m_Settings.PasswordIsEnabled; m_Clients.TryAdd(client.ClientID, _connectedClient); _connectedClient.Client.ClientSocket.Send(_connectedClient.TextEncoder.GetBytes(" \r\n" + getPromptText()));//Telnet ekranını temizlemek için if (_connectedClient.IsLoginRequired) { promptLogin(_connectedClient); } }
public event EventHandler <CommandRecievedEventArgs> CommandRecieved; // The event that notifies about a new Command being recieved #endregion /// <summary> /// constructor. /// </summary> /// <param name="controller">controller</param> /// <param name="logging">logger</param> public ImageServer(IImageController controller, ILoggingService logging, ICurrentRunLog currentLog) { m_controller = controller; m_logging = logging; m_currentLog = currentLog; m_ch = new ClientHandler(m_controller, m_logging); m_tcpserver = new TCPServer(port, m_ch, m_logging); // read from App config and put handlers in array of string. // string[] directories = ConfigurationManager.AppSettings.Get("Handler").Split(';'); foreach (string directoryPath in ConfigInfomation.Instance.handlerPaths) { // create handler for each path. CreateHandler(directoryPath); } m_controller.SpecialCommanndAppeared += SendCommand; // m_controller.SpecialCommanndAppeared += PassLog; // m_logging.MessageRecieved += m_ch.UpdateClientsNewLog; }
private void m_TCPServer_DataReceived(ITCPServer server, ClientInfo client, byte[] data) { ConnectedClient _connectedClient; if (!m_Clients.TryGetValue(client.ClientID, out _connectedClient)) { return; } if (data.Length == 0) { return; } if (data[0] == 127)//Ignore delete key { return; } //Ignore arrow keys if (data.Length == 3) { if (data[0] == 27 && data[1] == 91) { byte _thirdByte = data[2]; //65,66,67,68:Up,Down,Right,Left if (_thirdByte > 64 && _thirdByte < 69) { return; } } } int _startIndex = 0; do { if (data[_startIndex] == (byte)255)//Skip Telnet handshaking data { _startIndex += 3; } else { break; } }while (_startIndex <= data.Length - 1); if (_startIndex > data.Length - 1) { return; } string _textData = _connectedClient.TextEncoder.GetString(data, _startIndex, data.Length - _startIndex); if (_textData == "\b")//Backspace { if (_connectedClient.CommandBuffer.Length > 0) { _connectedClient.CommandBuffer = _connectedClient.CommandBuffer.Remove(_connectedClient.CommandBuffer.Length - 1); } _connectedClient.Client.ClientSocket.Send(new byte[] { 0x20, 0x08 }); return; } // Add to buffer _connectedClient.CommandBuffer += _textData; int _endOfLineIndex = _connectedClient.CommandBuffer.IndexOf('\r'); if (_endOfLineIndex > -1) { do { if (_endOfLineIndex > 0) { string _cmd = _connectedClient.CommandBuffer.Substring(0, _endOfLineIndex + 1).Replace("\r", "").Replace("\n", "").Trim(); if (!String.IsNullOrEmpty(_cmd)) { if (_connectedClient.IsLoginRequired)//Has not logged in yet { _connectedClient.CommandBuffer = String.Empty; if (String.Compare(m_Settings.Password, _cmd) == 0) { _connectedClient.IsLoginRequired = false; sendCommandResult(new ReceivedCommandItem() { Client = _connectedClient, CommandName = "login", IsSucceed = true, ResponseMessage = "Logged in." }); return; } else { _connectedClient.LoginTryCount++; sendCommandResult(new ReceivedCommandItem() { Client = _connectedClient, CommandName = "login", IsSucceed = false, ResponseMessage = "Invalid password." }); if (_connectedClient.LoginTryCount >= m_Settings.MaxLoginTryCount) { _connectedClient.Client.ClientSocket.Close(); return; } promptLogin(_connectedClient); return; } } else { ReceivedCommandItem _cmdInfo = new ReceivedCommandItem(); _cmdInfo.Client = _connectedClient; _cmdInfo.InputCommand = _cmd; m_ReceivedCommands.Enqueue(_cmdInfo); } } } _connectedClient.CommandBuffer = _connectedClient.CommandBuffer.Substring(_endOfLineIndex + 1); _endOfLineIndex = _connectedClient.CommandBuffer.IndexOf('\r'); }while (_endOfLineIndex > -1); } }
public HostService(ILogger <HostService> logger, ITCPServer server) { Logger = logger; Server = server; }
public void Run(RunPropertyModel runPropertyModel) { _tcpServer = new TCPServer(runPropertyModel.IPAddress, runPropertyModel.Port); _tcpServer.RecieveDataEvent += RecieveClientCommand; _tcpServer.Start(runPropertyModel.ClientsCount); }
public void Run(IPAddress iPAddress, int port, int countClients) { _tcpServer = new TCPServer(iPAddress, port); _tcpServer.RecieveDataEvent += RecieveClientCommand; _tcpServer.Start(countClients); }