Click here to Skip to main content
Licence 
First Posted 23 Feb 2002
Views 90,504
Bookmarked 25 times

Time Client (RFC868)

By | 6 Apr 2002 | Article
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 via e-mail.

My e-mail : Orkun GEDiK

License

About the Author

Orkun GEDiK

Software Developer (Senior)
ASTRON
Turkey Turkey

Member

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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalstrange result!!! Pinmembersonggunyoung23:02 1 Sep '10  
GeneralRe: strange result!!! Pinmembersonggunyong0:11 2 Sep '10  
GeneralDialog + separate thread Pinmemberbruno voisin6:17 20 Sep '03  
GeneralNeed More Help Pinmembermjdeibert4:04 14 May '03  
GeneralRe: Need More Help PinmemberAhmet Orkun GEDiK1:43 21 May '03  
GeneralCan't get the files to compile Pinmemberniverson10:11 16 Aug '02  
GeneralRe: Can't get the files to compile PinsussOGED11:20 16 Aug '02  
GeneralRe: Can't get the files to compile Pinmemberniverson12:16 16 Aug '02  
GeneralSlight Bug PinmemberJohn Burton2:19 8 Apr '02  
GeneralRe: Slight Bug PinmemberAhmet Orkun GEDiK9:10 8 Apr '02  
GeneralSomething wrong PinmemberDavide Zaccanti5:29 7 Apr '02  
GeneralRe: Something wrong PinmemberAhmet Orkun GEDiK9:46 7 Apr '02  
GeneralList of timeservers PinmemberAnonymous0:02 2 Mar '02  
A good example, there is a list of public timeservers:
http://www.eecis.udel.edu/~mills/ntp/clock1.htm
GeneralRe: List of timeservers (correction) PinmemberDavidCrow16:14 6 Apr '04  
GeneralSimple but useful example PinmemberAnonymous16:07 26 Feb '02  
GeneralRe: Simple but useful example PinmemberAhmet Orkun GEDiK1:04 27 Feb '02  
GeneralCut/Paste PinmemberTodd Jeffreys10:14 24 Feb '02  
GeneralRe: Cut/Paste PinmemberAhmet Orkun GEDiK10:32 25 Feb '02  
GeneralRe: Cut/Paste PinmemberPierre Couderc22:43 7 Apr '02  
GeneralRe: Cut/Paste PinmemberAhmet Orkun GEDiK9:11 8 Apr '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 7 Apr 2002
Article Copyright 2002 by Orkun GEDiK
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid