More .NET components

Daytime protocol

Daytime protocol is intended for testing and measurement purposes in computer networks. It was defined in 1983 by RFC 867 and runs over TCP or UDP port 13. Unlike Time protocol, it was not originally intended to be machine-readable, but this is not an issue for Rebex Daytime object.

Although it's not as accurate as more sophisticated SNTP/NTP protocol, it can run over TCP (unlike SNTP/NTP), which makes it useful in scenarios where UDP is not available.

Synchronizing system clock #

To synchronize local system time with a Daytime server, use SynchronizeSystemClock method:

CSharp

// create Time client instance
var client = new Rebex.Net.Daytime("test.rebex.net");

// synchronize local time with time server
client.SynchronizeSystemClock();

VisualBasic

' create Time client instance
Dim client = New Rebex.Net.Daytime("test.rebex.net")

' synchronize local time with time server
client.SynchronizeSystemClock()

Alternatively, the static variant of Daytime.SynchronizeSystemClock method makes it possible to synchronize system time with a single line of code:

CSharp

// synchronize system clock using Daytime protocol
Rebex.Net.Daytime.SynchronizeSystemClock("test.rebex.net");

VisualBasic

' synchronize system clock using Daytime protocol
Rebex.Net.Daytime.SynchronizeSystemClock("test.rebex.net")

System clock synchronization is supported on Windows, Windows CE and Linux operating systems.

Note: To update the system time, administrator privileges are needed. Check out the TimeWinFormClient sample code to see how to elevate the application to obtain them.

Getting server time #

To retrieve the current time from a Daytime server, call the GetTime method:

CSharp

// create Daytime client instance
var client = new Rebex.Net.Daytime("test.rebex.net");

// get current time at the server
DateTime now = client.GetTime();

VisualBasic

' create Daytime client instance
Dim client = New Rebex.Net.Daytime("test.rebex.net")

' get current time at the server
Dim now As DateTime = client.GetTime()

TCP and UDP #

Daytime protocol can be used over TCP and UDP protocols. Several other options are tweakable as well.

CSharp

// create Daytime client instance
var client = new Rebex.Net.Daytime(hostname, 13);

// use TCP instead of default UDP
client.UseTcp = true;

// set response timeout to 5 seconds
client.Timeout = 5000;

// retrieve remote time, synchronize system clock, etc.

VisualBasic

' create Daytime client instance
Dim client = New Rebex.Net.Daytime(hostname, 13)

' use TCP instead of default UDP
client.UseTcp = True

' set response timeout to 5 seconds
client.Timeout = 5000

' retrieve remote time, synchronize system clock, etc.