C# SNTP Client

Environment: Visual Studio.NET Beta 1

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. If Michel (or anyone else that knows it) reads this
and emails me, then I’ll update the article.

There are several time severs on the Internet and the list below contains those
operated by NIST. If you need more, you can probably find a few more using any standard Internet search engine.

Name IP Address Location
time-a.nist.gov NIST, Gaithersburg, Maryland
time-b.nist.gov NIST, Gaithersburg, Maryland
time-a.timefreq.bldrdoc.gov NIST, Boulder, Colorado
time-b.timefreq.bldrdoc.gov NIST, Boulder, Colorado
time-c.timefreq.bldrdoc.gov NIST, Boulder, Colorado
utcnist.colorado.edu University of Colorado, Boulder
time.nist.gov NCAR, Boulder, Colorado
time-nw.nist.gov Microsoft, Redmond, Washington
nist1.datum.com Datum, San Jose, California
nist1.dc.certifiedtime.com Abovnet, Virginia
nist1.nyc.certifiedtime.com Abovnet, New York City
nist1.sjc.certifiedtime.com Abovnet, San Jose, California

The server time.nist.gov yields the following results:

The NTPClient class is simply to use. Follow the example below:

NTPClient client;
client = new NTPClient("time.nist.gov");
catch(Exception e)
Console.WriteLine("ERROR: {0}", e.Message);


Download source – 4 Kb
Download demo project – 7 Kb

More by Author

Must Read