Time Shield Library
C++ library for working with time
Loading...
Searching...
No Matches
NTP Client

Facilities for retrieving time using the Network Time Protocol. More...

Files

file  ntp_client.hpp
 Simple NTP client for querying time offset from NTP servers.
 
file  wsa_guard.hpp
 Singleton guard for WinSock initialization.
 

Classes

class  time_shield::NtpClient
 Simple Windows-only NTP client for measuring time offset. More...
 
class  time_shield::WsaGuard
 Singleton guard for WinSock initialization. More...
 

Detailed Description

Facilities for retrieving time using the Network Time Protocol.

This module contains a minimal client capable of querying remote NTP servers to measure the offset between local and network time. It uses WinSock via the WsaGuard helper and therefore works only on Windows.

Features:

Example Usage:

if (client.query()) {
int64_t offset = client.get_offset_us();
int64_t utc_ms = client.get_utc_time_ms();
}
Simple Windows-only NTP client for measuring time offset.
int64_t get_offset_us() const noexcept
Returns the last measured offset in microseconds.
int64_t get_utc_time_ms() const noexcept
Returns current UTC time in milliseconds based on last NTP offset.
bool query()
Queries the NTP server and updates the local offset.