client1.start();
ClientSession session1 = client1.connect("localhost", port1).await().getSession();
assertTrue(session1.authAgent("smx").await().isSuccess());
ChannelShell channel1 = session1.createShellChannel();
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new TeePipedOutputStream(sent);
channel1.setIn(new PipedInputStream(pipedIn));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
channel1.setOut(out);
channel1.setErr(err);
channel1.setAgentForwarding(true);
channel1.open().await();
synchronized (shellFactory.shell) {
shellFactory.shell.wait();
}
SshClient client2 = SshClient.setUpDefaultClient();
client2.setAgentFactory(agentFactory);
client2.getProperties().putAll(shellFactory.shell.getEnvironment().getEnv());
client2.start();
ClientSession session2 = client2.connect("localhost", port2).await().getSession();
assertTrue(session2.authAgent("smx").await().isSuccess());
ChannelShell channel2 = session2.createShellChannel();
channel2.setIn(shellFactory.shell.getIn());
channel2.setOut(shellFactory.shell.getOut());
channel2.setErr(shellFactory.shell.getErr());
channel2.setAgentForwarding(true);
channel2.open().await();
pipedIn.write("foo\n".getBytes());
pipedIn.flush();
Thread.sleep(1000);
System.out.println(out.toString());
System.err.println(err.toString());