5,533,615 members and growing! (17,596 online)
Email Password   helpLost your password?
General Programming » Date and Time » Tools     Intermediate

Time Client (RFC868)

By Orkun GEDiK

Learn how to synchronize your date and time
VC6, VC7, C++Windows, NT4, Win2K, WinXP, MFC, VS6, Visual Studio, Dev

Posted: 23 Feb 2002
Updated: 6 Apr 2002
Views: 70,965
Bookmarked: 17 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
17 votes for this Article.
Popularity: 4.63 Rating: 3.76 out of 5
1 vote, 25.0%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 25.0%
4
2 votes, 50.0%
5

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 via e-mail.

My e-mail : Orkun GEDiK

License

About the Author

Orkun GEDiK


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.
Occupation: Web Developer
Location: Turkey Turkey

Other popular Date and Time articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 18 of 18 (Total in Forum: 18) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralDialog + separate threadmemberbruno voisin7:17 20 Sep '03  
GeneralNeed More Helpmembermjdeibert5:04 14 May '03  
GeneralRe: Need More HelpmemberAhmet Orkun GEDiK2:43 21 May '03  
GeneralCan't get the files to compilememberniverson11:11 16 Aug '02  
GeneralRe: Can't get the files to compilesussOGED12:20 16 Aug '02  
GeneralRe: Can't get the files to compilememberniverson13:16 16 Aug '02  
GeneralSlight BugmemberJohn Burton3:19 8 Apr '02  
GeneralRe: Slight BugmemberAhmet Orkun GEDiK10:10 8 Apr '02  
GeneralSomething wrongmemberDavide Zaccanti6:29 7 Apr '02  
GeneralRe: Something wrongmemberAhmet Orkun GEDiK10:46 7 Apr '02  
GeneralList of timeserversmemberAnonymous1:02 2 Mar '02  
GeneralRe: List of timeservers (correction)memberDavidCrow17:14 6 Apr '04  
GeneralSimple but useful examplememberAnonymous17:07 26 Feb '02  
GeneralRe: Simple but useful examplememberAhmet Orkun GEDiK2:04 27 Feb '02  
GeneralCut/PastememberTodd Jeffreys11:14 24 Feb '02  
GeneralRe: Cut/PastememberAhmet Orkun GEDiK11:32 25 Feb '02  
GeneralRe: Cut/PastememberPierre Couderc23:43 7 Apr '02  
GeneralRe: Cut/PastememberAhmet Orkun GEDiK10:11 8 Apr '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 6 Apr 2002
Editor: James Spibey
Copyright 2002 by Orkun GEDiK
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project