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

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

Introduction

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

Prototype

public void setDefaultTimeout(int timeout) 

Source Link

Document

Set the default timeout in milliseconds to use when opening a socket.

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);
    client.connect(host);/*from   w ww .  ja  v a2s.  c o m*/
    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 {/*from  w  w w .ja va  2  s. c  o  m*/
        // 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 ww.j  av a2s.co  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);
        try {//from w  w  w.j  av  a2  s  . c  o m
            client.connect(host);
            Date ntpDate = client.getDate();
            client.disconnect();
            return ntpDate;
        } catch (Exception exp) {
            System.out.println("NTP connection error");
        }
    }
    return null;
}