commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel F. Savarese" <>
Subject Re: Net - TelnetClient with linux
Date Wed, 18 Aug 2004 17:28:07 GMT

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 :)


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

View raw message