Example usage for org.apache.commons.net.ntp NtpV3Packet VERSION_4

List of usage examples for org.apache.commons.net.ntp NtpV3Packet VERSION_4

Introduction

In this page you can find the example usage for org.apache.commons.net.ntp NtpV3Packet VERSION_4.

Prototype

int VERSION_4

To view the source code for org.apache.commons.net.ntp NtpV3Packet VERSION_4.

Click Source Link

Usage

From source file:experts.net.ip6.ULUA.java

/**
 * Obtain NTP time stamp value//from  w ww  . j a va2  s .c o  m
 *
 * @param address
 *            NTP server address
 * @return the current time of day in 64-bit NTP format
 * @throws SocketException
 *             If the socket could not be opened which it might be not available any ports.
 * @throws UnknownHostException
 *             If the host could not be found.
 * @throws IOException
 */
public static long obtainNTPTime(String address) throws SocketException, UnknownHostException, IOException {
    NTPUDPClient client = new NTPUDPClient();
    client.setVersion(NtpV3Packet.VERSION_4);

    // throws SocketException
    client.open();
    // throws UnknownHostException from InetAddress.getByName and IOException from client.getTime
    TimeInfo time = client.getTime(InetAddress.getByName(address));
    client.close();

    time.computeDetails();

    return time.getMessage().getTransmitTimeStamp().ntpValue();
}