You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@mina.apache.org by kranga <kr...@k2d2.org> on 2009/09/05 22:24:24 UTC

[sshd] Does anyone have an example of a very simple ShellFactory.Shell implementation?

I'm trying to create a simple shell that takes the input and echoes it back. I thought in the start method, I could create a thread that simply read int from the inputstream and wrote to the outputstream. However, I notice that when I start typing in putty, everything is ignored (SSH_MSG_IGNORE) and nothing makes its way to my shell. 

Perhaps my shell code is too simple? Can anyone provide a sample? Here is my Shell implementation:

public class SimpleShell implements Shell, Runnable {

private OutputStream _errorStream;
private InputStream _inputStream;
private OutputStream _outputStream;



public void destroy() {
}



public void setErrorStream(OutputStream stream) {
_errorStream = stream;
}



public void setExitCallback(ExitCallback arg0) {
}


 

public void setInputStream(InputStream stream) {
_inputStream = stream;
}


public void setOutputStream(OutputStream stream) {
_outputStream = stream;
}


public void start(Environment arg0) throws IOException {
Thread thread = new Thread(this);
thread.start();
_outputStream.write("Hello> ".getBytes());
_outputStream.flush();
}


 

public void run() {
int i = 0;
try {
while ((i = _inputStream.read()) != -1) {
_outputStream.write(i);
}
} catch (IOException e) {
e.printStackTrace();
}
}





}

Re: [sshd] Does anyone have an example of a very simple ShellFactory.Shell implementation?

Posted by kranga <kr...@k2d2.org>.
I figured that I need to call flush just after I sent the email. But it 
seems the NioProcessor continues to log SSH_MSG_IGNORE messages. I take it 
that is harmless.

Thanks for the response!

--------------------------------------------------
From: "Guillaume Nodet" <gn...@gmail.com>
Sent: Monday, September 07, 2009 2:27 AM
To: <us...@mina.apache.org>
Subject: Re: [sshd] Does anyone have an example of a very simple 
ShellFactory.Shell implementation?

> We have the following test class:
>
> http://svn.apache.org/repos/asf/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java
>
> It looks roughly the same as yours, but I think what you're missing is a
> call to _outputStream.flush() each time you write something to the stream.
>
> On Sat, Sep 5, 2009 at 22:24, kranga <kr...@k2d2.org> wrote:
>
>> I'm trying to create a simple shell that takes the input and echoes it
>> back. I thought in the start method, I could create a thread that simply
>> read int from the inputstream and wrote to the outputstream. However, I
>> notice that when I start typing in putty, everything is ignored
>> (SSH_MSG_IGNORE) and nothing makes its way to my shell.
>>
>> Perhaps my shell code is too simple? Can anyone provide a sample? Here is
>> my Shell implementation:
>>
>> public class SimpleShell implements Shell, Runnable {
>>
>> private OutputStream _errorStream;
>> private InputStream _inputStream;
>> private OutputStream _outputStream;
>>
>>
>>
>> public void destroy() {
>> }
>>
>>
>>
>> public void setErrorStream(OutputStream stream) {
>> _errorStream = stream;
>> }
>>
>>
>>
>> public void setExitCallback(ExitCallback arg0) {
>> }
>>
>>
>>
>>
>> public void setInputStream(InputStream stream) {
>> _inputStream = stream;
>> }
>>
>>
>> public void setOutputStream(OutputStream stream) {
>> _outputStream = stream;
>> }
>>
>>
>> public void start(Environment arg0) throws IOException {
>> Thread thread = new Thread(this);
>> thread.start();
>> _outputStream.write("Hello> ".getBytes());
>> _outputStream.flush();
>> }
>>
>>
>>
>>
>> public void run() {
>> int i = 0;
>> try {
>> while ((i = _inputStream.read()) != -1) {
>> _outputStream.write(i);
>> }
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>> }
>>
>>
>>
>>
>>
>> }
>>
>
>
>
> -- 
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> ------------------------
> Open Source SOA
> http://fusesource.com
> 

Re: [sshd] Does anyone have an example of a very simple ShellFactory.Shell implementation?

Posted by Guillaume Nodet <gn...@gmail.com>.
We have the following test class:

http://svn.apache.org/repos/asf/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/EchoShellFactory.java

It looks roughly the same as yours, but I think what you're missing is a
call to _outputStream.flush() each time you write something to the stream.

On Sat, Sep 5, 2009 at 22:24, kranga <kr...@k2d2.org> wrote:

> I'm trying to create a simple shell that takes the input and echoes it
> back. I thought in the start method, I could create a thread that simply
> read int from the inputstream and wrote to the outputstream. However, I
> notice that when I start typing in putty, everything is ignored
> (SSH_MSG_IGNORE) and nothing makes its way to my shell.
>
> Perhaps my shell code is too simple? Can anyone provide a sample? Here is
> my Shell implementation:
>
> public class SimpleShell implements Shell, Runnable {
>
> private OutputStream _errorStream;
> private InputStream _inputStream;
> private OutputStream _outputStream;
>
>
>
> public void destroy() {
> }
>
>
>
> public void setErrorStream(OutputStream stream) {
> _errorStream = stream;
> }
>
>
>
> public void setExitCallback(ExitCallback arg0) {
> }
>
>
>
>
> public void setInputStream(InputStream stream) {
> _inputStream = stream;
> }
>
>
> public void setOutputStream(OutputStream stream) {
> _outputStream = stream;
> }
>
>
> public void start(Environment arg0) throws IOException {
> Thread thread = new Thread(this);
> thread.start();
> _outputStream.write("Hello> ".getBytes());
> _outputStream.flush();
> }
>
>
>
>
> public void run() {
> int i = 0;
> try {
> while ((i = _inputStream.read()) != -1) {
> _outputStream.write(i);
> }
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
>
>
>
>
>
> }
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com