The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version 0.06

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 hexidecimal.

An example:

          'Root Delay' => '0.001220703125',
          'Version Number' => 3,
          'Precision' => -19,
          'Leap Indicator' => 0,
          'Transmit Timestamp' => '1239808045.86401',
          'Receive Timestamp' => '1239808045.86398',
          'Stratum' => 2,
          'Originate Timestamp' => '1239808045.24414',
          'Reference Timestamp' => '1239807468.92445',
          'Poll Interval' => '0.0000',
          'Reference Clock Identifier' => '193.79.237.14',
          'Mode' => 4,
          'Root Dispersion' => '0.0000'

SEE ALSO

Net::NTP

POE

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

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

AUTHORS

  • Chris Williams <chris@bingosnet.co.uk>

  • James G. Willmore

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Chris Williams and James G. Willmore.

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