Click here to Skip to main content
13,259,771 members (47,963 online)
Click here to Skip to main content
Add your own
alternative version


96 bookmarked
Posted 13 Mar 2001

SNTP Client in C#

, 27 Aug 2001
Rate this:
Please Sign up or sign in to vote.
Implementation of the Simple Network Time Protocol (RFC 2030) in C#
  • Download source files - 12 Kb
  • Download demo project - 5 Kb

    Sample Image - ntpclient.jpg


    Though not obvious, time synchronization is sometimes important. The best example is the Kerberos authentication protocol, which requires the resources to be synchronized within minutes or even seconds, but there are other situations as well. The Network Time Protocol (NTP) and its simplified form (SNTP) are widely used to synchronize network resources, due to their simplicity and effectiveness. There are many programs available that synchronize your PC's clock with that of a time server. Dimension 4 is my favorite.

    In case you need time synchronization embedded into your software, here is the C# alternative. It's simple, fast and integrates seamlessly with the .NET platform. There is a Java implementation of a NTP client by Michel Van den Bergh, but I don't have the URL anymore. Maybe Michel reads this and will send me a note.

    There are several time severs on the Internet and the list below contains those operated by NIST. If you need more, use a search engine.

    NameIP AddressLocation
    time-a.nist.gov129.6.15.28NIST, Gaithersburg, Maryland
    time-b.nist.gov129.6.15.29NIST, Gaithersburg, Maryland
    time-a.timefreq.bldrdoc.gov132.163.4.101NIST, Boulder, Colorado
    time-b.timefreq.bldrdoc.gov132.163.4.102NIST, Boulder, Colorado
    time-c.timefreq.bldrdoc.gov132.163.4.103NIST, Boulder, Colorado
    utcnist.colorado.edu128.138.140.44University of Colorado, Boulder
    time.nist.gov192.43.244.18NCAR, Boulder, Colorado
    time-nw.nist.gov131.107.1.10Microsoft, Redmond, Washington
    nist1.datum.com209.0.72.7Datum, San Jose, California
    nist1.dc.certifiedtime.com216.200.93.8Abovnet, Virginia, New York City
    nist1.sjc.certifiedtime.com208.185.146.41Abovnet, San Jose, California

  • License

    This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


    About the Author

    Valer BOCAN
    Romania Romania
    I am a software engineer based in Timișoara, Romania and currently hold the position of software architect for one of the largest companies in the world.

    I invented a dialect of the Forth programming language and implemented the first Forth compiler for the .NET platform. I reverse-engineered the communication protocol of some GPS trackers and wrote from scratch a vehicle tracking system that is currently used to track my two cars. I hold a PhD in computer science and I am the author of several papers and a book chapter. In the 90s I wrote several computer viruses in assembly language for my own research and I was the first to devise a technique to deter heuristic virus scanners. In short, a humble man.

    You may also be interested in...

    Comments and Discussions

    GeneralExecution on Pocket PC Emulator Pin
    Rashmi C13-Dec-06 2:16
    memberRashmi C13-Dec-06 2:16 
    GeneralGet Server time Pin
    try.kret8-Oct-06 18:14
    membertry.kret8-Oct-06 18:14 
    AnswerRe: Get Server time Pin
    Valer BOCAN8-Oct-06 18:23
    memberValer BOCAN8-Oct-06 18:23 
    GeneralRe: Get Server time Pin
    try.kret8-Oct-06 18:49
    membertry.kret8-Oct-06 18:49 
    GeneralRe: Get Server time Pin
    try.kret9-Oct-06 16:32
    membertry.kret9-Oct-06 16:32 
    QuestionUrgent:- Implementation of the Network Time protocol (RFC 13905) in C++ Pin
    Kulkarni Abhijit27-Jul-06 1:49
    memberKulkarni Abhijit27-Jul-06 1:49 
    GeneralThanks!! Pin
    Micah Wedemeyer23-Dec-05 5:24
    memberMicah Wedemeyer23-Dec-05 5:24 
    GeneralUsing IP addresses rather than hostnames Pin
    MrEyes27-May-05 6:46
    memberMrEyes27-May-05 6:46 
    Firstly let me say that this is an excellent class an extremely useful.

    That being said, I am encountering a small problem that hopefully somebody could shed some light on.

    If I pass an IP address to the SNTPClient constructor it always returns succesful, even if the IP doesnt exist. As an example:

    client = new SNTPClient(""); //this ip doesnt exist and cannot be pinged or telnetted to port 123

    Doesnt throw any exceptions and returns this

    Leap Indicator: No warning
    Version number: 3
    Mode: Server
    Stratum: Secondary Reference
    Local time: 27/05/2005 16:29:39
    Precision: 9.5367431640625E-07 s
    Poll Interval: 1 s
    Reference ID: (
    Root Delay: 34.912109375 ms
    Root Dispersion: 90.972900390625 ms
    Round Trip Delay: 1 ms
    Local Clock Offset: 0 ms

    I have to admit, I have no idea where the reference ID is coming from.

    If I use a non existant host name (e.g. foobar) it does throw an exception.

    post.mode = postmodes.signature;
    SELECT everything FROM everywhere WHERE something = something_else;
    > 1 Row Returned
    > 42
    GeneralNeed urgent Help Pin
    PShweta7-Oct-04 0:59
    memberPShweta7-Oct-04 0:59 
    GeneralRe: Need urgent Help Pin
    Valer BOCAN7-Oct-04 1:53
    memberValer BOCAN7-Oct-04 1:53 
    Generalminor bug : Peer clock precision calculation Pin
    EzekielDA10-Jun-04 12:40
    memberEzekielDA10-Jun-04 12:40 
    GeneralRe: minor bug : Peer clock precision calculation Pin
    Valer BOCAN14-Jun-04 7:02
    memberValer BOCAN14-Jun-04 7:02 
    GeneralDoesn't Run on WinXP Pro Pin
    sandman_max4-May-04 3:36
    membersandman_max4-May-04 3:36 
    GeneralRe: Doesn't Run on WinXP Pro Pin
    Valer BOCAN14-Jun-04 7:04
    memberValer BOCAN14-Jun-04 7:04 
    GeneralDoesn't work with W2K server Pin
    rahulN19-Jan-04 23:29
    memberrahulN19-Jan-04 23:29 
    GeneralRe: Doesn't work with W2K server Pin
    Valer BOCAN3-Feb-04 1:20
    memberValer BOCAN3-Feb-04 1:20 
    GeneralWindows CE Compatibility Pin
    RFID Chris4-Dec-03 6:59
    memberRFID Chris4-Dec-03 6:59 
    GeneralJava implementation of a NTP client by Michel Van den Bergh, Pin
    Kavitha Gopal21-Oct-03 22:45
    sussKavitha Gopal21-Oct-03 22:45 
    GeneralRe: Java implementation of a NTP client by Michel Van den Bergh, Pin
    Anonymous29-Sep-05 7:25
    sussAnonymous29-Sep-05 7:25 
    GeneralServer Timeout Pin
    wey978-Jul-03 6:42
    memberwey978-Jul-03 6:42 
    GeneralRe: Server Timeout Pin
    nolazabal11-Nov-04 13:08
    membernolazabal11-Nov-04 13:08 
    AnswerRe: Server Timeout Pin
    jdn492927-Apr-06 11:31
    memberjdn492927-Apr-06 11:31 
    GeneralRe: Server Timeout Pin
    segato20-Jun-06 3:18
    membersegato20-Jun-06 3:18 
    GeneralRe: Server Timeout Pin
    djlove24-Feb-09 23:52
    memberdjlove24-Feb-09 23:52 
    AnswerRe: Server Timeout Pin
    dazza19763-Mar-08 21:26
    memberdazza19763-Mar-08 21:26 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
    Web01 | 2.8.171114.1 | Last Updated 28 Aug 2001
    Article Copyright 2001 by Valer BOCAN
    Everything else Copyright © CodeProject, 1999-2017
    Layout: fixed | fluid