Example usage for org.apache.commons.net.time TimeTCPClient disconnect

List of usage examples for org.apache.commons.net.time TimeTCPClient disconnect

Introduction

In this page you can find the example usage for org.apache.commons.net.time TimeTCPClient disconnect.

Prototype

public void disconnect() throws IOException 

Source Link

Document

Disconnects the socket connection.

Usage

From source file:examples.unix.rdate.java

public static final void timeTCP(String host) throws IOException {
    TimeTCPClient client = new TimeTCPClient();

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);//  w ww  .  j  av  a  2  s  .c om
    client.connect(host);
    System.out.println(client.getDate().toString());
    client.disconnect();
}

From source file:beans.TimeClient.java

public static final void timeTCP(String host) throws IOException {
    TimeTCPClient client = new TimeTCPClient();
    try {/*  w w  w .j ava2 s . c om*/
        // We want to timeout if a response takes longer than 60 seconds
        client.setDefaultTimeout(60000);
        client.connect(host);
        System.out.println(client.getDate());
    } finally {
        client.disconnect();
    }
}

From source file:it.jnrpe.plugin.CheckTime.java

private Date getTimeTCP(String host, int timeout, int port) throws IOException {
    TimeTCPClient client = new TimeTCPClient();
    client.setDefaultPort(port);/*  w w  w  .  java2 s.c o  m*/
    client.setDefaultTimeout((int) TimeUnit.SECOND.convert(timeout));
    client.connect(host);
    Date date = client.getDate();
    client.disconnect();
    return date;

}

From source file:org.techytax.util.DateHelper.java

public static Date getNTPDate() {
    List<String> hosts = Collections.singletonList("nl.pool.ntp.org");

    for (String host : hosts) {
        TimeTCPClient client = new TimeTCPClient();
        client.setDefaultTimeout(5000);//from   w w w .j a  va  2  s  . c o  m
        try {
            client.connect(host);
            Date ntpDate = client.getDate();
            client.disconnect();
            return ntpDate;
        } catch (Exception exp) {
            System.out.println("NTP connection error");
        }
    }
    return null;
}