You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Anjib Mulepati <an...@hotmail.com> on 2014/09/08 17:52:52 UTC

[net] Handling sequence of sendCommand()

Hi All,

    

    I am using this AutomatedTelnetClient (http://stackoverflow.com/questions/1195809/looking-for-java-telnet-emulator)
      to send sequence of command to telehack.com:23. 
AutomatedTelnetClient telnet = new AutomatedTelnetClient("telehack.com", "23");
telnet.sendCommand("rand ");//run OK
telnet.sendCommand("cal "); //run OK
telnet.sendCommand("date "); //never run


    first two command run OK and gives me
        output but third one never runs. I change the order of cal and
        date this time rans and date execute but not cal. So it running
        first two commands only.

        

        So my question is do I have to use some kind of thread in that
        program to do read and write operation from the telnet server?

        

        Thanks,

        Anjib  		 	   		  

Re: [net] Handling sequence of sendCommand()

Posted by sebb <se...@gmail.com>.
On 9 September 2014 00:29, sebb <se...@gmail.com> wrote:
> On 8 September 2014 16:52, Anjib Mulepati <an...@hotmail.com> wrote:
>> Hi All,
>>
>>
>>
>>     I am using this AutomatedTelnetClient (http://stackoverflow.com/questions/1195809/looking-for-java-telnet-emulator)
>>       to send sequence of command to telehack.com:23.
>> AutomatedTelnetClient telnet = new AutomatedTelnetClient("telehack.com", "23");
>> telnet.sendCommand("rand ");//run OK
>> telnet.sendCommand("cal "); //run OK
>> telnet.sendCommand("date "); //never run
>>
>>
>>     first two command run OK and gives me
>>         output but third one never runs. I change the order of cal and
>>         date this time rans and date execute but not cal. So it running
>>         first two commands only.
>
> Could try adding a dummy command at the end as a temporary work-round.
> But that should not be necessary.
>
>>
>>
>>         So my question is do I have to use some kind of thread in that
>>         program to do read and write operation from the telnet server?
>>
>
> That should not be necessary - TelnetClient is intended for use from a
> single thread.
>
> See the sample code here:
> http://commons.apache.org/proper/commons-net/examples/telnet/TelnetClientExample.java

I just noticed that this does use a reader thread, but this is
intended for interactive use, rather than as an automated app.
It's not actually necessary to use a separate thread, so long as the
app reads the output in a timely manner.

If the app does not read all the responses, I suppose it's possible
that the buffers could fill up and cause stalling.
But it looks as though the app does keep reading until it sees the
command prompt.

Though the readUntil() method might perhaps be fooled by a prompt
sequence embedded within the output.
It should be obvious if this is happening since the responses are
written to the screen.

To avoid this possibility, it could keep reading until there is no
more output available *and* the prompt is at the end.



> However, there have been some fixes which have not yet been released,
> including one which relates to EOL handling.
> That could perhaps cause the problems you are seeing.
>
> So it might be worth trying the current code from SVN.
> There's a more recent version of the example as well.
>
>>
>>         Thanks,
>>
>>         Anjib

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [net] Handling sequence of sendCommand()

Posted by sebb <se...@gmail.com>.
On 8 September 2014 16:52, Anjib Mulepati <an...@hotmail.com> wrote:
> Hi All,
>
>
>
>     I am using this AutomatedTelnetClient (http://stackoverflow.com/questions/1195809/looking-for-java-telnet-emulator)
>       to send sequence of command to telehack.com:23.
> AutomatedTelnetClient telnet = new AutomatedTelnetClient("telehack.com", "23");
> telnet.sendCommand("rand ");//run OK
> telnet.sendCommand("cal "); //run OK
> telnet.sendCommand("date "); //never run
>
>
>     first two command run OK and gives me
>         output but third one never runs. I change the order of cal and
>         date this time rans and date execute but not cal. So it running
>         first two commands only.

Could try adding a dummy command at the end as a temporary work-round.
But that should not be necessary.

>
>
>         So my question is do I have to use some kind of thread in that
>         program to do read and write operation from the telnet server?
>

That should not be necessary - TelnetClient is intended for use from a
single thread.

See the sample code here:
http://commons.apache.org/proper/commons-net/examples/telnet/TelnetClientExample.java

However, there have been some fixes which have not yet been released,
including one which relates to EOL handling.
That could perhaps cause the problems you are seeing.

So it might be worth trying the current code from SVN.
There's a more recent version of the example as well.

>
>         Thanks,
>
>         Anjib

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


RE: [net] Handling sequence of sendCommand()

Posted by Anjib Mulepati <an...@hotmail.com>.
So is that mean TelnetClient run those command in different thread and parallel?

telnet.sendCommand("rand "); telnet.sendCommand("cal "); and telnet.sendCommand("date "); running at same time?
If yes can you explain me why third command never executed or give output?


From: mgainty@hotmail.com
To: anjibcs@hotmail.com
Subject: RE: [net] Handling sequence of sendCommand()
Date: Mon, 8 Sep 2014 14:58:51 -0400






  


> From: anjibcs@hotmail.com
> To: user@commons.apache.org
> Subject: [net] Handling sequence of sendCommand()
> Date: Mon, 8 Sep 2014 10:52:52 -0500
> 
> Hi All,
> 
> 
> 
> I am using this AutomatedTelnetClient (http://stackoverflow.com/questions/1195809/looking-for-java-telnet-emulator)
> to send sequence of command to telehack.com:23. 
> AutomatedTelnetClient telnet = new AutomatedTelnetClient("telehack.com", "23");
> telnet.sendCommand("rand ");//run OK
> telnet.sendCommand("cal "); //run OK
> telnet.sendCommand("date "); //never run
> 
> 
> first two command run OK and gives me
> output but third one never runs. I change the order of cal and
> date this time rans and date execute but not cal. So it running
> first two commands only.
> 
> 
> 
> So my question is do I have to use some kind of thread in that
> program to do read and write operation from the telnet server?
MG>you want the cycle of input, process, output to complete for each command
MG>before moving onto the next
MG>a blocking thread in combination with a synchronizer would handle this for you
MG>https://today.java.net/pub/a/today/2008/10/23/creating-a-notifying-blocking-thread-pool-executor.html#the-need-for-a-blocking-thread-pool
> 
> 
> 
> Thanks,
> 
> Anjib