List of usage examples for org.apache.commons.net.time TimeTCPClient TimeTCPClient
public TimeTCPClient()
From source file:beans.TimeClient.java
public static final void timeTCP(String host) throws IOException { TimeTCPClient client = new TimeTCPClient(); try {/*from ww w . j a va2s . com*/ // 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: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);//from w w w. jav a2 s . c o m client.connect(host); System.out.println(client.getDate().toString()); 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);//from w ww. j av a2 s. 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);/*from w w w . j ava 2 s. c om*/ try { client.connect(host); Date ntpDate = client.getDate(); client.disconnect(); return ntpDate; } catch (Exception exp) { System.out.println("NTP connection error"); } } return null; }