Meaningless Drivel is fun!*
The moose likes Other Application Frameworks and the fly likes telnet client timeout using BufferedInputStream Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "telnet client timeout using BufferedInputStream" Watch "telnet client timeout using BufferedInputStream" New topic
Author

telnet client timeout using BufferedInputStream

terry Kiernan
Ranch Hand

Joined: Aug 23, 2008
Posts: 31
Hi,
I have a case where by i am using BufferedInputStream I am waiting for the response I have sent within the telnet session.
If the response is what I expect all is fine, However if the response is not what the application expects the session hangs and won't time out ...
This is my code i have below: can you spot something why this piece of code will not time out when it has finished reading the number of bytes and hasn't found the matchString. ?
Your help much appreciated !

WaitResponse waitingFor(String[] tokens, long timeout) throws IOException {
long start = System.currentTimeMillis();
long deadline = start + timeout;

StringBuffer response = new StringBuffer();
String matchingToken = null;
for (; null == matchingToken; matchingToken = match(response, tokens)) {
int charread = 0;
while ((charread = is.read(mB, 0, mB.length)) <= 0) {
long now = System.currentTimeMillis();
if (now > deadline) {
throw new IOTimeoutException(TimedOut);
}
try {
Thread.sleep(THREAD_SLEEP_TIME);
} catch (InterruptedException ignored) {
}
}
String mS = new String(mB, 0, charread);
logger.print(mS);
response.append(mS);
logger.flush();
}

return new WaitResponse(response.toString(), matchString);
}
[ December 08, 2008: Message edited by: terry Kiernan ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: telnet client timeout using BufferedInputStream
 
Similar Threads
performance Issue
StringBuffer not outperforming "+"
Socket closed exception while downloading heavy files
Suggestions on fastest way to parse a String?
Strings and StringBuffer