Example usage for org.apache.commons.net.bsd RLoginClient DEFAULT_PORT

List of usage examples for org.apache.commons.net.bsd RLoginClient DEFAULT_PORT

Introduction

In this page you can find the example usage for org.apache.commons.net.bsd RLoginClient DEFAULT_PORT.

Prototype

int DEFAULT_PORT

To view the source code for org.apache.commons.net.bsd RLoginClient DEFAULT_PORT.

Click Source Link

Document

The default rlogin port.

Usage

From source file:com.qspin.qtaste.tcom.rlogin.RLogin.java

/**
 * Reboot the remote host by sending the reboot command and check that
 * the remote host is not accessible anymore.
 * @return true if success, false otherwise
 *//*w  w w .j  av  a  2  s.  com*/
public boolean reboot() {
    if (!sendCommand("reboot")) {
        return false;
    }

    // wait 1 second
    try {
        Thread.sleep(1000);
    } catch (InterruptedException ex) {
    }

    disconnect();

    // check that remote host is not accessible anymore
    // open a socket without any parameters. It hasn't been binded or connected
    Socket socket = new Socket();
    try {
        // bind to a local ephemeral port
        socket.bind(null);
        socket.connect(new InetSocketAddress(remoteHost, RLoginClient.DEFAULT_PORT), 1);
    } catch (SocketTimeoutException e) {
        logger.info("Rebooted host " + remoteHost + " successfully");
        return true;
    } catch (IOException e) {
        logger.error("Something went wrong while rebooting host:" + remoteHost);
        return false;
    } finally {
        try {
            socket.close();
        } catch (IOException ex) {
        }
        socket = null;
    }
    // Expected to get an exception as the remote host should not be reachable anymore
    logger.error("Host " + remoteHost
            + " did not reboot as expected! Please check that no other rlogin client is connected!");
    return false;
}