/** ** Main client thread loop */ public void run() { this.setRunStatus(THREAD_RUNNING); this.threadStarted(); try { this.openSocket(); this.inputThread = new InputThread(this.socket, this.readTimeout, this.ioThreadLock); this.outputThread = new OutputThread(this.socket, this.ioThreadLock); this.inputThread.start(); this.outputThread.start(); synchronized (this.ioThreadLock) { while (this.inputThread.isRunning() || this.outputThread.isRunning()) { try { this.ioThreadLock.wait(); } catch (Throwable t) { } } } } catch (NoRouteToHostException nrthe) { Print.logInfo("Client:ControlThread - Unable to reach " + this.host + ":" + this.port); nrthe.printStackTrace(); } catch (Throwable t) { Print.logInfo("Client:ControlThread - " + t); t.printStackTrace(); } finally { this.closeSocket(); } this.setRunStatus(THREAD_STOPPED); this.threadStopped(); }
private static void usage() { Print.logInfo("Usage:"); Print.logInfo(" java ... " + ClientSocketThread.class.getName() + " {options}"); Print.logInfo("'Send' Options:"); Print.logInfo(" -host=<host> The destination host"); Print.logInfo(" -port=<port> The destination port"); Print.logInfo(" -send=<data> The data to send (prefix with '0x' for hex data)"); Print.logInfo("'Receive' Options (not yet implemented):"); Print.logInfo(" -port=<port> The port on which to listen for incoming data"); Print.logInfo(" -recv Set to 'receive' mode"); System.exit(1); }
public void run() { String command = null; Print.logInfo("Client:OutputThread started"); while (true) { /* wait for commands */ synchronized (this.cmdList) { while ((this.cmdList.size() <= 0) && (getRunStatus() == THREAD_RUNNING)) { try { this.cmdList.wait(5000L); } catch (Throwable t) { /*ignore*/ } } if (getRunStatus() != THREAD_RUNNING) { break; } command = this.cmdList.remove(0).toString(); } /* send commands */ try { ClientSocketThread.socketWriteLine(this.socket, command); } catch (Throwable t) { Print.logError("Client:OutputThread - " + t); t.printStackTrace(); break; } } if (getRunStatus() == THREAD_RUNNING) { Print.logWarn("Client:OutputThread stopped due to error"); } else { Print.logInfo("Client:OutputThread stopped"); } synchronized (this.threadLock) { this.isRunning = false; Print.logInfo("Client:OutputThread stopped"); this.threadLock.notify(); } }