2 Attachment(s)
[VB6] SNTPClient UserControl
This is a basic Simple Network Time Protocol (SNTP) client UserControl based on a Winsock control that can be used to retrieve time from NIST Internet Time Servers or local NTP servers on your LAN.
It includes a 4 second "delay" to prevent overuse (minimum of 4.1 seconds between Query method calls) with an Unblock event to signal when another request can be made. See the NIST page linked above.
Since NTP servers return UTC (GMT) time, there is also a method to convert the UTC result returned through the Response event to local time. Response also returns the Source of the time as reported by the time server (if any). Typical values are listed in RFC 5905 as:
Code:
+------+----------------------------------------------------------+
| ID | Clock Source |
+------+----------------------------------------------------------+
| GOES | Geosynchronous Orbit Environment Satellite |
| GPS | Global Position System |
| GAL | Galileo Positioning System |
| PPS | Generic pulse-per-second |
| IRIG | Inter-Range Instrumentation Group |
| WWVB | LF Radio WWVB Ft. Collins, CO 60 kHz |
| DCF | LF Radio DCF77 Mainflingen, DE 77.5 kHz |
| HBG | LF Radio HBG Prangins, HB 75 kHz |
| MSF | LF Radio MSF Anthorn, UK 60 kHz |
| JJY | LF Radio JJY Fukushima, JP 40 kHz, Saga, JP 60 kHz |
| LORC | MF Radio LORAN C station, 100 kHz |
| TDF | MF Radio Allouis, FR 162 kHz |
| CHU | HF Radio CHU Ottawa, Ontario |
| WWV | HF Radio WWV Ft. Collins, CO |
| WWVH | HF Radio WWVH Kauai, HI |
| NIST | NIST telephone modem |
| ACTS | NIST telephone modem |
| USNO | USNO telephone modem |
| PTB | European telephone modem |
+------+----------------------------------------------------------+
These are not particularly useful in most programs though.
The attached demo shows use of the SNTPClient control, which is included in the attached archive.
To use the control in your own programs just copy SNTPClient.ctl and SNTPClient.ctx to your Project folder and add the module to your Project.
Re: [VB6] SNTPClient UserControl
I see that some NTP servers return "garbage" in the ReferenceIdentifier field of the response ("Source" as reported by the Response event).
For example, time.windows.com returns as response like:
Code:
0000 1c 02 00 fa 00 00 08 00 00 00 0c 12 0a 14 e5 33 ...............3
0010 d6 69 c3 15 83 e2 fb 0c 00 00 00 00 00 00 00 00 .i..............
0020 d6 69 c3 3b 4b d2 98 be d6 69 c3 3b 4b d2 98 be .i.;K....i.;K...
While time.nist.gov returns:
Code:
0000 1c 01 00 e3 00 00 00 00 00 00 00 00 41 43 54 53 ............ACTS
0010 d6 69 c3 a5 e0 f5 4e ee 00 00 00 00 00 00 00 00 .i....N.........
0020 d6 69 c3 cc 45 87 65 75 d6 69 c3 cc 45 87 e8 b5 .i..E.eu.i..E...
... as documented and expected.
Re: [VB6] SNTPClient UserControl
For those who don't know what NTP (or SNTP) is all about... it gives you a very lightweight way to request time from a server when you can't trust the local clock.
No webscraping, no need to rely on web services that may disappear tomorrow.
This can be handy for a lot of things, even for time-limited trial versions of your programs.