in reply to NTP Error
1. If the NTP server is not reachable then it exits the script and i never get any error message as such. Can i add error handling here ?
A quick look inside the module shows that if any error occurs; the module dies with an error.
So, you can either allow that error to be displayed directly; or you could use block eval to trap it within your script:
#! perl -slw use strict; use Data::Dump qw[ pp ]; use Net::NTP qw[ get_ntp_response ]; my %resp; eval{ %resp = get_ntp_response( '0.poll.ntp.org' ); 1; } or die $@; pp \%resp;
Not that there would be much point if all you are going to do is die yourself; but you get the point.
If the way i am trying to get time the right way ?
This is a more complex question.
The reason for having the four timestamps in the response, is intended to allow the user to access the correctness of time returned.
In a typical repsonse:
C:\test>ntp { "Leap Indicator" => 0, Mode => 4, "Originate Timestamp" => "1338194114.66406", "Poll Interval" => "0.0000", Precision => -22, "Receive Timestamp" => "1338194119.80861", "Reference Clock Identifier" => "195.66.241.3", "Reference Timestamp" => "1338192423.2336", "Root Delay" => "0.00360107421875", "Root Dispersion" => "0.0000", Stratum => 2, "Transmit Timestamp" => "1338194119.80867", "Version Number" => 3, }
You can see by subtracting the time when the server recieved the request ("Receive Timestamp") from the time the client included in the request ("Originate Timestamp") that the packet took a little over 5 seconds to reach the server.
So, the server has factored that in, so that when it sends the response at ("Transmit Timestamp") 1338194119.80867, it adds that delay to the ("Reference Timestamp"), 1338192423.2336, so by the time you receive it, it should be pretty close to spot on.
Of course, if you delay utilising it at your end -- say, by letting it get caught up in interminable layers of some redundant behemoth of an IO library like POE -- then your just throwing away all work the NTP protocol uses to try and achieve accuracy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: NTP Error
by rduke15 (Beadle) on Jan 11, 2016 at 00:16 UTC | |
by BrowserUk (Patriarch) on Jan 11, 2016 at 04:19 UTC |