I am developing a Command Line Interface simulator with sshd.
I have some problems trying to understand how to use client side streams to
interact with the server.

I would like to have a client that sends a command to the server, then,
blocks waiting for the response from the server: I would like to have a
client that reads from the communication channel and block until the
channel is full with something (a blocking read from the input stream would
be great).

How can I obtain such behaviour?

I started modifying org.apache.sshd.ClientTest


       SshClient client = SshClient.setUpDefaultClient();
        client.start();
        ClientSession session = client.connect("localhost",
port).await().getSession();
        session.authPassword("smx", "smx").await().isSuccess();
        ClientChannel channel =
session.createChannel(ClientChannel.CHANNEL_SHELL);

        ByteArrayOutputStream sent = new ByteArrayOutputStream();
        PipedOutputStream pipedIn = new PipedOutputStream();
        channel.setIn(new PipedInputStream(pipedIn));
        OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        channel.setOut(out);
        channel.setErr(err);
        channel.open();

        teeOut.write("this is my command\n".getBytes());
        teeOut.flush();

but I Was not able to obtain the desired effect.

thanks

Davide

Reply via email to