News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Get time from server

Started by Dark Schneider, February 05, 2012, 03:00:14 AM

Previous topic - Next topic

Dark Schneider

Is there any time server that support simple winsock TCP/IP connection?
NTP looks complicated and I just want to read current time from a server to verify something in my program (I want it to stop working on a specific date), not to sync time to my PC.

dedndave

the NIST supports a few different protocols
http://www.nist.gov/pml/div688/grp40/its.cfm
http://tf.nist.gov/tf-cgi/servers.cgi

this one seems pretty simple   :P
Daytime Protocol (RFC-867)

This protocol is widely used by small computers running MS-DOS
and similar operating systems. The server listens on port 13,
and responds to requests in either tcp/ip or udp/ip formats.

Dark Schneider

Strange....
I used IP addresses from http://tf.nist.gov/tf-cgi/servers.cgi that says "All services available" and
I tried to connect to port 13 but I got disconnected immediately without any data sent from the servers.


dedndave

have a look here
http://www.nist.gov/pml/div688/grp40/acts.cfm
you simply connect, then it sends you a string every second

QuoteACTS works at speeds up to 9600 baud with 8 data bits, 1 stop bit, and no parity.
To receive the full time code, you must connect at a speed of at least 1200 baud.
The full time code is transmitted every second and contains more information than
the 300 baud time code, which is transmitted every 2 seconds.

Dark Schneider

QuoteACTS only works with analog modems that use ordinary telephone lines. Digital modems, such as Digital Subscriber Line (DSL), cable and wireless modems, cannot synchronize using ACTS. For computers with Internet access, the Internet Time Service should be used to synchronize to NIST.

It won't work with modern modems?
And the fact that it send time in plain text, I think that make it too easy for someone who might try to fool the program to think it's not expiration date.

Maybe I'll have to implement a NTP client after all.

I've never used UDP before, look at this...

http://www.networksorcery.com/enp/protocol/ntp.htm

What is MAC header, IP header and UDP header?


EDIT:
Oh wait.
I tried again with "time-A.timefreq.bldrdoc.gov" (132.163.4.101) and it sent me a time string.

55962 12-02-05 16:40:36 00 0 0 927.0 UTC(NIST) *

So, not every time server support RFC-867.

dedndave

well - there is another option
even simpler, because you do not need to parse a string
QuoteTime Protocol (RFC-868)

This simple protocol is now used by only about 1% of ITS customers.
It returns a 32-bit unformatted binary number that represents the
time in UTC seconds since January 1, 1900. The server listens for
Time Protocol requests on port 37, and responds in either tcp/ip
or udp/ip formats. Conversion to local time (if necessary) is the
responsibility of the client program. The 32-bit binary format can
represent times over a span of about 136 years with a resolution
of 1 second. There is no provision for increasing the resolution or
increasing the range of years.

The strength of the time protocol is its simplicity. Since many
computers keep time internally as the number of seconds since
January 1, 1970 (or another date), converting the received time
to the necessary format is often a simple matter of binary arithmetic.
However, the format does not allow any additional information to be
transmitted, such as advance notification of leap seconds or daylight
saving time, or information about the health of the server.

QuoteThe Time Protocol is a network protocol in the Internet Protocol Suite
defined in 1983 in RFC 868. Its purpose is to provide a site-independent,
machine readable date and time.

The Time Protocol may be implemented over the Transmission Control
Protocol (TCP) or the User Datagram Protocol (UDP). A host connects
to a server that supports the Time Protocol on port 37. The server
then sends the time as a 32-bit unsigned integer in binary format and
in network byte order, representing the number of seconds since 00:00
(midnight) 1 January, 1900 GMT, and closes the connection. Operation
over UDP requires the sending of any datagram to the server port, as
there is no connection setup for UDP.

qWord

I've played a bit with it - see attachment

qWord
FPU in a trice: SmplMath
It's that simple!

dedndave

nice   :U
although - it froze on me, one time - can't make it happen again

MichaelW

I can reliably make it freeze by overlapping multiple connections, but I suspect that this is just the server protecting itself from people who would otherwise endlessly screw with it.
eschew obfuscation

qWord

Quote from: MichaelW on February 05, 2012, 10:49:19 PM
server protecting itself from people who would otherwise endlessly screw with it.
that is also my assumption.
This problem should solved by using WSAEventSelect ()+WSAWaitForMultipleEvents().
FPU in a trice: SmplMath
It's that simple!

clive

Quote from: qWordI've played a bit with it - see attachment

Yes, basically sending an empty packet to an NTP server will get a time stamped response, and for the most part this is sufficient unless you want to dance around trying to deal with the travel time to get sub-second synchronization.

I've tended to use pool.ntp.org:123 although in the long distance past I used to use tick and tock.usnogps.navy.mil due to it's use in the ground portion of GPS, but this is probably not advisable these days.  http://tycho.usno.navy.mil/ntp.html

Converting NTP time to UNIX time is a matter of correcting the difference in the epochs.
It could be a random act of randomness. Those happen a lot as well.

Dark Schneider

The console is invisible so I have to kill process. I never like console so I edit it a bit.

This is easier to use than RFC-867 and I can use it with any time servers in my country too, all of them don't support RFC-867.