Beispiel #1
0
        public static void Client(Config config, Action <ITestShell, string> action)
        {
            using (var disposer = new Disposer())
            {
                var client   = SocketTools.ConnectWithTimeout(config.ShellIP, config.ShellPort, 2000);
                var endpoint = client.Client.LocalEndPoint as IPEndPoint;
                var stream   = SocketTools.SslWithTimeout(client, 2000);
                var read     = new StreamReader(stream);
                var write    = new StreamWriter(stream);
                //var passfile = ExecutableTools.Relative("Password.txt");
                //var password = File.ReadAllText(passfile).Trim();
                //write.WriteLine(password);
                var shell  = new TestShell();
                var reader = new Runner(new Runner.Args {
                    ThreadName = "SOCKIN"
                });
                var writer = new Runner(new Runner.Args {
                    ThreadName = "SOCKOUT"
                });
                reader.Run(() =>
                {
                    var line = read.ReadLine();
                    while (line != null)
                    {
                        Logger.Trace("<c {0}", line);
                        shell.WriteLine("<c {0}", line);
                        line = read.ReadLine();
                    }
                });
                writer.Run(() =>
                {
                    var line = shell.ReadLine();
                    while (line != null)
                    {
                        Logger.Trace("c> {0}", line);
                        write.WriteLine(line);
                        write.Flush();
                        line = shell.ReadLine();
                    }
                });
                disposer.Push(reader);
                disposer.Push(client);
                disposer.Push(writer);
                disposer.Push(shell);

                //netcore linux prints ipv6 in endpoint.tostring
                action(shell, $"{config.ShellIP}:{endpoint.Port}");
            }
        }