List of usage examples for org.apache.commons.net.time TimeUDPClient TimeUDPClient
TimeUDPClient
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);//from w ww . j a v a 2 s . c o m client.open(); System.out.println(client.getDate(InetAddress.getByName(host))); client.close(); }
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);/*from w w w . ja v a2 s. c o m*/ client.open(); System.out.println(client.getDate(InetAddress.getByName(host)).toString()); client.close(); }
From source file:com.nubits.nubot.NTP.NTPClient.java
private Date getTimeImpl(String host) throws IOException { Date toRet;//from ww w . ja v a 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.greenvulcano.util.remotefs.RemoteManager.java
/** * Return current time on the remote FTP server. * // w w w . j ava 2 s. c om * @return the current time on the remote FTP server. */ public long getRemoteTime() { boolean useLocalTime = true; long time = -1; try { if (timeUdpClient == null) { timeUdpClient = new TimeUDPClient(); } timeUdpClient.setDefaultTimeout(1000); timeUdpClient.open(); time = (timeUdpClient.getTime(InetAddress.getByName(hostname)) - TimeUDPClient.SECONDS_1900_TO_1970) * 1000; timeUdpClient.close(); useLocalTime = false; } catch (Exception exc) { logger.warn("Could not detect server time: " + exc); time = System.currentTimeMillis(); } finally { logger.debug((useLocalTime ? "LOCAL" : "REMOTE") + " machine time [" + time + "]: " + new Date(time)); } return time; }
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();/*from www . j a va 2 s .c o m*/ Date date = client.getDate(InetAddress.getByName(host)); client.close(); return date; }