rsntp
An RFC 4330 compliant Simple Network Time Protocol (SNTP) client library for Rust.
rsntp
provides an API to synchronize time with SNTPv4 time servers with the following features:
- Provides both a synchronous (blocking) and an (optional) asynchronous API based
tokio
- Time and date handling based on the
chrono
crate - IPv6 support
Usage
Add this to your Cargo.toml
:
[]
= "2.0.0"
Obtain the current local time with the blocking API:
use SntpClient;
use ;
let client = new;
let result = client.synchronize.unwrap;
let local_time: = from;
println!;
A function which uses the asynchronous API to obtain local time:
use AsyncSntpClient;
use ;
async
Disabling asynchronous API
The asynchronous API is enabled by default but you can optionally disable it. This removes
dependency to tokio
which reduces crate dependencies significantly.
[]
= { = "2.0.0", = false }
IPv6 support
rsntp
supports IPv6, but by default (for compatilibty reasons) it binds its UDP socket to an
IPv4 address (0.0.0.0) which might prevent synchronization with IPv6 servers.
To use IPv6, you need to set an IPv6 bind address:
use ;
use SntpClient;
use Ipv6Addr;
let mut client = new;
client.set_bind_address;
let result = client.synchronize.unwrap;
let local_time: = from;