This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

telnet client timeout using BufferedInputStream

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
The human mind is a dangerous plaything. This tiny ad is pretty safe:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!