Examples of NTPUDPClient


Examples of org.apache.commons.net.ntp.NTPUDPClient

    {
        long currentTime = System.currentTimeMillis();

        InetAddress host = InetAddress.getByName( null );

        NTPUDPClient ntp = new NTPUDPClient();
        ntp.setDefaultTimeout( 500000 );

        TimeInfo timeInfo = ntp.getTime( host, port );
        long returnTime = timeInfo.getReturnTime();
        assertTrue( currentTime - returnTime < 1000 );

        timeInfo.computeDetails();
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

        if (args.length == 0) {
            System.err.println("Usage: NTPClient <hostname-or-address-list>");
            System.exit(1);
        }

        NTPUDPClient client = new NTPUDPClient();
        // We want to timeout if a response takes longer than 10 seconds
        client.setDefaultTimeout(10000);
        try {
            client.open();
            for (int i = 0; i < args.length; i++)
            {
                System.out.println();
                try {
                    InetAddress hostAddr = InetAddress.getByName(args[i]);
                    System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress());
                    TimeInfo info = client.getTime(hostAddr);
                    processResponse(info);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }

        client.close();
    }
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

    // Fails with a timeout !!!
    public void testNtp() throws Exception
    {
        InetAddress host = InetAddress.getByName( null );

        NTPUDPClient ntp = new NTPUDPClient();
        ntp.setDefaultTimeout( 500000 );

        long currentTime = System.currentTimeMillis();
        TimeInfo timeInfo = ntp.getTime( host, port );
        long returnTime = timeInfo.getReturnTime();
        assertTrue( Math.abs( currentTime - returnTime ) < 1000 );

        timeInfo.computeDetails();
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

    // Fails with a timeout !!!
    public void testNtp() throws Exception
    {
        InetAddress host = InetAddress.getByName( null );

        NTPUDPClient ntp = new NTPUDPClient();
        ntp.setDefaultTimeout( 500000 );

        long currentTime = System.currentTimeMillis();
        TimeInfo timeInfo = ntp.getTime( host, port );
        long returnTime = timeInfo.getReturnTime();
        assertTrue( Math.abs( currentTime - returnTime ) < 1000 );

        timeInfo.computeDetails();
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

    @Ignore // Fails with a timeout !!!
    public void testNtp() throws Exception
    {
        InetAddress host = InetAddress.getByName( null );

        NTPUDPClient ntp = new NTPUDPClient();
        ntp.setDefaultTimeout( 500000 );

        long currentTime = System.currentTimeMillis();
        TimeInfo timeInfo = ntp.getTime( host, port );
        long returnTime = timeInfo.getReturnTime();
        assertTrue( Math.abs( currentTime - returnTime ) < 1000 );

        timeInfo.computeDetails();
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

        if (args.length == 0) {
            System.err.println("Usage: NTPClient <hostname-or-address-list>");
            System.exit(1);
        }

        NTPUDPClient client = new NTPUDPClient();
        // We want to timeout if a response takes longer than 10 seconds
        client.setDefaultTimeout(10000);
        try {
            client.open();
            for (String arg : args)
            {
                System.out.println();
                try {
                    InetAddress hostAddr = InetAddress.getByName(arg);
                    System.out.println("> " + hostAddr.getHostName() + "/" + hostAddr.getHostAddress());
                    TimeInfo info = client.getTime(hostAddr);
                    processResponse(info);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }

        client.close();
    }
View Full Code Here

Examples of org.apache.commons.net.ntp.NTPUDPClient

   * error occurs.
   */
  protected static long getTime(String hostname) {
   
    try {
      NTPUDPClient timeClient = new NTPUDPClient();
      timeClient.setDefaultTimeout(NTP_TIMEOUT);
      InetAddress inetAddress = InetAddress.getByName(hostname);
      TimeInfo timeInfo = timeClient.getTime(inetAddress);
     
      return timeInfo.getReturnTime();
    }
    catch (UnknownHostException uhe) {
      logger.warn("the given hostname '{}' of the timeserver is unknown -> returning current sytem time instead", hostname);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.