Chris Williams > POE-Component-Client-NTP > POE::Component::Client::NTP

Download:
POE-Component-Client-NTP-0.14.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.14   Source  

NAME ^

POE::Component::Client::NTP - A POE Component to query NTP servers

VERSION ^

version 0.14

SYNOPSIS ^

  use strict;
  use warnings;
  use POE qw(Component::Client::NTP);
  use Data::Dumper;

  my $host = shift or die "Please specify a host name to query\n";

  POE::Session->create(
    package_states => [
            main => [qw(_start _response)],
    ],
  );

  $poe_kernel->run();
  exit 0;

  sub _start {
    POE::Component::Client::NTP->get_ntp_response(
       host => $host,
       event => '_response',
    );
    return;
  }

  sub _response {
    my $packet = $_[ARG0];
    print Dumper( $packet );
    return;
  }

DESCRIPTION ^

POE::Component::Client::NTP is a POE component that provides Network Time Protocol (NTP) client services to other POE sessions and components.

NTP is a protocol for synchronising the clocks of computer systems over data networks and is described in RFC 1305 and RFC 2030.

The code in this module is derived from Net::NTP by James G. Willmore

CONSTRUCTOR ^

get_ntp_response

Takes a number of options, only those marked as mandatory are required:

  'event', the event to emit when completed, mandatory;
  'session', provide an alternative session to send the resultant event to;
  'host', the name/address of the NTP server to query, default is 'localhost';
  'port', the UDP port to send the query to, default is 123;
  'timeout', the number of seconds to wait for a response, default is 60 seconds;
  'context', any reference data you wish to receive in the response event;

The session parameter is only required if you wish the output event to go to a different session than the calling session, or if you have spawned the poco outside of a session.

OUTPUT EVENT ^

This is generated by the poco. ARG0 will be a hash reference with the following keys:

  'response', this will be a HASHREF on success;
  'host', the host string that was passed to the constructor;
  'error', on failure this will be defined, with an error string;
  'context', whatever was passed to the constructor;

The response hashref will contain various parts of the NTP response packet as outlined in RFC1305. Like Net::NTP some of the data will be normalised/humanised, such as timestamps are in epoch, NOT hexadecimal.

Hexadecimal timestamps are available for Reference, Originate and Transmit as hex_ref_time, hex_org_time and hex_trans_time, respectively.

An example:

   'Version Number' => 3,
   'Mode' => 4,
   'Stratum' => 3,
   'Poll Interval' => '3.0000',
   'Reference Clock Identifier' => '46.254.216.9'
   'Precision' => -21,
   'Root Delay' => '0.0540924072265625',
   'Delay' => '0.01513',
   'Leap Indicator' => 0,
   'Root Dispersion' => '0.0000',
   'Originate Timestamp' => '1423758184.59018',
   'Transmit Timestamp' => '1423758184.17864',
   'Receive Timestamp' => '1423758184.17854',
   'Reference Timestamp' => '1423757055.50512',
   'Offset' => '-0.00148022174835205',
   'hex_org_time' => 'd88751e8.232d70e5',
   'hex_trans_time' => 'd88751e8.aa5e272',
   'hex_ref_time' => 'd8874d7f.1e1b7956',

SEE ALSO ^

Net::NTP

POE

http://www.faqs.org/rfcs/rfc1305.html

http://www.faqs.org/rfcs/rfc2030.html

AUTHORS ^

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2015 by Chris Williams and James G. Willmore and Ask Bjørn Hansen.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: