commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Diogo Saad" <>
Subject RES: Net - TelnetClient with linux
Date Fri, 20 Aug 2004 15:06:45 GMT
I tryed to read from the stream til I get -1 , but I never got it for my
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
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:"  ???


> -----Mensagem original-----
> De: Daniel F. Savarese [] 
> Enviada em: quarta-feira, 18 de agosto de 2004 14:28
> Para:
> Assunto: Re: Net - TelnetClient with linux 
> In message <010001c483c4$24ae7c20$0700a8c0@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:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message