Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: sockets: problems with daytime client

by gmargo (Hermit)
on Jan 20, 2010 at 15:53 UTC ( [id://818490]=note: print w/replies, xml ) Need Help??


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

    Before asking my question here, I visited all the links in your post while looking for public daytime servers, but I couldn't get any host to work. My program just hung. Now things seem to be working.

    All I was trying to do was retrieve a line of text from a remote host to see if I could get a simple networking program to work.

    Thanks.
      mahbe should have tried HTTP instead, your browser conn seems to work :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://818490]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-03-29 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found