Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Time Client (RFC868)

0.00/5 (No votes)
6 Apr 2002 1  
Learn how to synchronize your date and time

Introduction

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.)

  1. S: Listen on port 37 (45 octal)
  2. U: Connect to port 37
  3. S: Send the time as a 32 bit binary number
  4. U: Receive the time
  5. U: Close the connection
  6. 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.

For example:

  • 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.

License

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.

License

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