in reply to sockets: problems with daytime client
I can't seem to find a public daytime server
A Google search for
public daytime server
rapidly finds the
National Institute of Standards and Technology,
which runs
NTP and
DAYTIME
servers.
See Set Your Computer Clock Via the Internet and NIST Internet Time Servers.
Your next challenge is to write a DAYTIME server, and configure launchd on your own system to run it on demand.
The following modification of your code will parse the NIST standard DAYTIME format.
use strict; use warnings; #use 5.010; use IO::Socket; #my $host = 'localhost'; #my $host = 'time.nist.gov'; #my $host = 'nist1-sj.ustiming.org'; my $host = 'time-nw.nist.gov'; # pester microsoft my $port = 'daytime(13)'; my $sock = IO::Socket::INET->new( Proto => 'tcp', PeerHost => $host, PeerPort => $port, ) or die "cannot connect: $!"; while (<$sock>) { s/^[[:space:]]+//; s/[[:space:]]+\z//s; next if /^$/; # NIST Daytime Protocol format # http://tf.nist.gov/service/its.htm # JJJJJ YR-MO-DA HH:MM:SS TT L H msADV UTC(NIST) OTM if ($_ =~ /^(\d+)\s+(\d{2})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2}):(\d{ +2})\s+(\d{2})\s+(\d)\s+(\d)\s+([0-9\.]+)\s+UTC\(NIST\)\s+(.)/) { my ($mjd, $yr, $mo, $da) = ($1,$2,$3,$4); my ($hour, $min, $sec, $dst, $lsec) = ($5,$6,$7,$8,$9); my ($health, $msADV, $otm) = ($10,$11,$12); print "NIST: $yr-$mo-$da $hour:$min:$sec\n"; } else { print "$_\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: sockets: problems with daytime client
by 7stud (Deacon) on Jan 24, 2010 at 12:01 UTC | |
by Anonymous Monk on Jan 24, 2010 at 12:31 UTC |