More .NET libraries
-
Rebex Total Pack
All Rebex .NET libraries together
Back to feature list...
Daytime protocol
On this page:
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:
// create Time client instance var client = new Rebex.Net.Daytime("test.rebex.net"); // synchronize local time with time server client.SynchronizeSystemClock();
' 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:
// synchronize system clock using Daytime protocol Rebex.Net.Daytime.SynchronizeSystemClock("test.rebex.net");
' 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:
// create Daytime client instance var client = new Rebex.Net.Daytime("test.rebex.net"); // get current time at the server DateTime now = client.GetTime();
' 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.
// 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.
' 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.
Back to feature list...