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;
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.)
- S: Listen on port 37 (45 octal)
- U: Connect to port 37
- S: Send the time as a 32 bit binary number
- U: Receive the time
- U: Close the connection
- S: Close the connection
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.
- 2,208,988,800 corresponds to 00:00 1 Jan 1970 GMT
- 2,398,291,200 corresponds to 00:00 1 Jan 1976 GMT
- 2,524,521,600 corresponds to 00:00 1 Jan 1980 GMT
- 2,629,584,000 corresponds to 00:00 1 May 1983 GMT
- and -1,297,728,000 corresponds to 00:00 17 Nov 1858 GMT.
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 below.
This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.
A list of licenses authors might use can be found here.
I'm working at Yasar Holding IT department as senior SAP R/3 BASIS and Development Consultant and system integrator. I have experience on C/C++ for 6 years. Implementing and inviting new technologies is most biggest part of my life. Object oriented paradigm is a philosophy of my vision.