You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Daniel F. Savarese" <df...@savarese.org> on 2004/08/18 19:28:07 UTC

Re: Net - TelnetClient with linux

In message <01...@macale>, "Diogo Saad" writes:
>Now I tryed to use it into a linux machine and I got some problems!!
>When I try to read() all available data from telnet inputstream it
>returns a splited string ( not with all the content)...

There's nothing wrong going on.  The same thing can happen on any
system given your implementation (it may simply take a larger amount
of data and different network conditions on your other system).  If
your intent is to read all of the data from the stream, then don't use
available().  When available() returns 0 it does not mean the end of
stream has been reached.  It just means there's no data available to
read from the stream's buffer at that moment.  Instead, check to see if
read returns -1, indicating the end of stream has been reached.  If your
intent is to read only the data that is actually available to read at
a given time, then you have to structure your calls to your String read()
method to take into account the fact that data can arrive in
fragments.  The only reason to use available() is to simulate non-blocking
I/O.  So either you want your String read() to be non-blocking or you don't.
If you want it to be non-blocking, you're getting exactly the behavior you
want.  If you want it to block, accumulating all data until the end of
stream is reached, test the return value of int read(...) in your loop.
If you want to do something else: need more data :)

daniel



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


RES: Net - TelnetClient with linux

Posted by Diogo Saad <di...@ibnetwork.com.br>.
I tryed to read from the stream til I get -1 , but I never got it for my
testcase
I guess it never reaches the end of the stream, cause it's expecting for
me to login (see below)


root@aragao # telnet aragao 4555
Trying 192.168.0.6...
Connected to aragao.
Escape character is '^]'.
JAMES Remote Administration Tool 2.2.0RC5
Please enter your login and password
Login id:


So how do I read a String that contains "JAMES Remote Administration
Tool 2.2.0RC5\nPlease enter your login and password\nLogin id:"  ???


Thanks 
Diogo




> -----Mensagem original-----
> De: Daniel F. Savarese [mailto:dfs@savarese.org] 
> Enviada em: quarta-feira, 18 de agosto de 2004 14:28
> Para: commons-user@jakarta.apache.org
> Assunto: Re: Net - TelnetClient with linux 
> 
> 
> 
> In message <01...@macale>, "Diogo 
> Saad" writes:
> >Now I tryed to use it into a linux machine and I got some problems!! 
> >When I try to read() all available data from telnet inputstream it 
> >returns a splited string ( not with all the content)...
> 
> There's nothing wrong going on.  The same thing can happen on 
> any system given your implementation (it may simply take a 
> larger amount of data and different network conditions on 
> your other system).  If your intent is to read all of the 
> data from the stream, then don't use available().  When 
> available() returns 0 it does not mean the end of stream has 
> been reached.  It just means there's no data available to 
> read from the stream's buffer at that moment.  Instead, check 
> to see if read returns -1, indicating the end of stream has 
> been reached.  If your intent is to read only the data that 
> is actually available to read at a given time, then you have 
> to structure your calls to your String read() method to take 
> into account the fact that data can arrive in fragments.  The 
> only reason to use available() is to simulate non-blocking 
> I/O.  So either you want your String read() to be 
> non-blocking or you don't. If you want it to be non-blocking, 
> you're getting exactly the behavior you want.  If you want it 
> to block, accumulating all data until the end of stream is 
> reached, test the return value of int read(...) in your loop. 
> If you want to do something else: need more data :)
> 
> daniel
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 


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