![]() |
General Programming »
Date and Time »
Tools
Intermediate
Time Client (RFC868)By Orkun GEDiKLearn how to synchronize your date and time |
VC6, VC7Win2K, WinXP, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
This article describes a time client which uses RFC 868 protocol. The program uses TCP port 37 for connection with a time server. This is a MFC based console application.
The following block calculates current date and time.
lnTime = (long)((sBuffer - (unsigned long)(DATE_1970))); Time_Int64 = Int32x32To64(lnTime, 10000000) + 116444736000000000; FileTime.dwLowDateTime = (DWORD)Time_Int64; FileTime.dwHighDateTime = Time_Int64 >> 32; FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &SystemTime); SetLocalTime( &SystemTime );
The time is calculated and converted to 64-bit in the first and second lines and then converted to local time zone before being converted to a SYSTEMTIME structure. Last of all the system time is set.
The following is the procedure for communicating with the time server. (These notes are copied from http://www.faqs.org/rfcs/rfc868.html )
The server listens for a connection on port 37. When the connection is established, the server returns a 32-bit time value and closes the connection. If the server is unable to determine the time at its site, it should either refuse the connection or close it without sending anything. The most important thing is, the time is the number of seconds since 00:00 (midnight) 1 January 1900 GMT, such that the time 1 is 12:00:01 am on 1 January 1900 GMT; this base will serve until the year 2036.
For example:
You can use the time.ien.it time service for testing (settime time.ien.it).I hope you have enjoyed with my time client. You can send any bug or comments via e-mail.
My e-mail : Orkun GEDiK
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Apr 2002 Editor: James Spibey |
Copyright 2002 by Orkun GEDiK Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |