commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel F. Savarese" <>
Subject Re: RES: Net - TelnetClient with linux
Date Thu, 26 Aug 2004 16:29:47 GMT

In message <002d01c486c7$4f05f1a0$0700a8c0@macale>, "Diogo Saad" writes:
>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)
>So how do I read a String that contains "JAMES Remote Administration
>Tool 2.2.0RC5\nPlease enter your login and password\nLogin id:"  ???

If you're implementing expect-like behavior, you have to do it in the
usual way which has little to do with Commons Net.  You have to read input
into a buffer until a particular expected length is reached or you
find a particular expected pattern.  In the case you describe, you
know the length of the data you expect to read, so just call
read(byte[], int offset, int length) until the desired amount of data has
been read and double check that it ends with "Login id:"  You can store
the data in separate buffer or allocate a sufficiently large byte array
and advance the offset and decrement the length on each read that returns
less data than you expect.  That is if you want to save the data, otherwise
just discard it if you're not searching for a pattern and are just reading
a specific number of bytes.


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

View raw message