You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Anthony Webster <aw...@tentelemed.com> on 2008/02/28 11:54:35 UTC

Trouble with TelnetClient use

Hello all,

 

I’m having a bit of trouble with the TelnetClient class. Up until recently
my code worked fine using the readUntil strategy:

 

private String readUntil(String pattern) throws Exception

{

char lastChar = pattern.charAt(pattern.length() - 1);

            StringBuffer sb = new StringBuffer();

            char ch = (char) in.read();

            while (true) {

sb.append(ch);

                        if (ch == lastChar) {

                                   if (sb.toString().endsWith(pattern)) {

                                               return sb.toString();

                                   }

                        }

                        ch = (char) in.read();

            }

}

 

I simply read from the TelnetClient’s InputStream until I encounter a
specified character or chain of characters. 

 

This worked fine but now I’m confronted with a situation (telneting to a
LinkStar satellite modem) where the format of command returns can vary from
day to day and there is not prompt character which I can key off (all I get
is a blinking underscore). This makes parsing command results near
impossible.

 

I was wondering if anyone here had encountered similar problems and how they
had been solved.

 

Many Thanks in advance

 

Anthony WEBSTER

Telemedicine Technologies S.A.

88, rue du Dôme

92100, Boulogne-Billancourt

 

T : +33 1 55 20 08 04

F : +33 1 49 10 06 52