Package org.apache.commons.net.ntp

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


        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();

        assertTrue( 0 < timeInfo.getOffset() && timeInfo.getOffset() < 1000 );
        assertTrue( 0 < timeInfo.getDelay() && timeInfo.getDelay() < 1000 );
    }
View Full Code Here


            {
                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();
                }
            }
View Full Code Here

        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();

        String offsetMsg = "Expected offset in range (-1000, 1000), but was " + timeInfo.getOffset();
        assertTrue( offsetMsg, -1000 < timeInfo.getOffset() && timeInfo.getOffset() < 1000 );
        String delayMsg = "Expected delay in range [0, 1000), but was " + timeInfo.getOffset();
        assertTrue( delayMsg, 0 <= timeInfo.getDelay() && timeInfo.getDelay() < 1000 );
    }
View Full Code Here

        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();

        String offsetMsg = "Expected offset in range (-1000, 1000), but was " + timeInfo.getOffset();
        assertTrue( offsetMsg, -1000 < timeInfo.getOffset() && timeInfo.getOffset() < 1000 );
        String delayMsg = "Expected delay in range [0, 1000), but was " + timeInfo.getOffset();
        assertTrue( delayMsg, 0 <= timeInfo.getDelay() && timeInfo.getDelay() < 1000 );
    }
View Full Code Here

        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();

        String offsetMsg = "Expected offset in range (-1000, 1000), but was " + timeInfo.getOffset();
        assertTrue( offsetMsg, -1000 < timeInfo.getOffset() && timeInfo.getOffset() < 1000 );
        String delayMsg = "Expected delay in range [0, 1000), but was " + timeInfo.getOffset();
        assertTrue( delayMsg, 0 <= timeInfo.getDelay() && timeInfo.getDelay() < 1000 );
    }
View Full Code Here

            {
                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();
                }
            }
View Full Code Here

   
    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);
    }
    catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of org.apache.commons.net.ntp.TimeInfo

Copyright © 2018 www.massapicom. 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.