|
- package net.hoo2.auth.vmodem;
-
- class Echo {
- static final int ECHO_DURATION_DEFAULT = 240;
- static final int ECHO_BUFFER_SIZE = 256;
- static final String ECHO_BEGIN = "PSTART";
- static final String ECHO_END = "PSTOP";
-
- private Com com_;
- private Log log_;
- private Transaction transaction_;
- private int duration_;
- private byte[] code_;
-
- Echo (Com com, Log log, byte[] code, int duration) {
- com_ = com;
- log_ = log;
- duration_ = duration;
- transaction_= new Transaction(null, new byte[ECHO_BUFFER_SIZE]);
- code_ = code;
- }
-
- void caption (byte[] code) {
- String line;
-
- line = "Running ECHO with: " + new String(code);
- log_.write(line, true);
-
- transaction_ = com_.request (transaction_, null, null, null, false);
- line = new String(transaction_.getResponse());
- log_.out(line);
- }
-
- void run () {
- long start;
- long now;
- String line;
-
- start = System.currentTimeMillis();
- do {
- transaction_ = com_.request(transaction_, code_, ECHO_BEGIN.getBytes(), ECHO_END.getBytes(), false);
- line = new String(transaction_.code) + ": "
- + new String(transaction_.getResponse())
- + " Tr= " + (transaction_.arrival - transaction_.departure) + " [msec]";
- log_.write(line);
- now = System.currentTimeMillis();
- } while (now - start < duration_*1000);
- }
-
- }
|