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

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

Introduction

In this page you can find the example usage for org.apache.commons.net.time TimeUDPClient 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 timeUDP(String host) throws IOException {
    TimeUDPClient client = new TimeUDPClient();

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);
    client.open();//w  w w  .  j  a v a 2  s .  c o m
    System.out.println(client.getDate(InetAddress.getByName(host)).toString());
    client.close();
}

From source file:beans.TimeClient.java

public static final void timeUDP(String host) throws IOException {
    TimeUDPClient client = new TimeUDPClient();

    // We want to timeout if a response takes longer than 60 seconds
    client.setDefaultTimeout(60000);
    client.open();//from  ww w. j  a  v  a 2 s .c o  m
    System.out.println(client.getDate(InetAddress.getByName(host)));
    client.close();
}

From source file:com.nubits.nubot.NTP.NTPClient.java

private Date getTimeImpl(String host) throws IOException {
    Date toRet;//www.  j  a  va 2  s .  c o m
    TimeUDPClient client = new TimeUDPClient();
    // We want to timeout if a response takes longer than TIMEOUT seconds
    client.setDefaultTimeout(TIMEOUT);
    client.open();
    toRet = client.getDate(InetAddress.getByName(host));
    client.close();

    return toRet;
}

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

private Date getTimeUDP(String host, int timeout) throws IOException {
    TimeUDPClient client = new TimeUDPClient();
    client.setDefaultTimeout((int) TimeUnit.SECOND.convert(timeout));
    client.open();/*  w ww  .j a v a2s .c  om*/
    Date date = client.getDate(InetAddress.getByName(host));
    client.close();
    return date;
}