sntpc-net-tokio

Crates.iosntpc-net-tokio
lib.rssntpc-net-tokio
version1.0.1
created_at2026-01-08 11:30:11.926872+00
updated_at2026-01-08 13:16:05.456021+00
descriptionTokio socket wrapper for sntpc library
homepage
repositoryhttps://github.com/vpetrigo/sntpc
max_upload_size
id2030014
size25,228
Vladimir Petrigo (vpetrigo)

documentation

README

GitHub Actions Workflow Status Crates.io docs.rs

sntpc-net-tokio

Tokio async runtime UDP socket adapter for the sntpc SNTP client library.

Design Goal

This crate provides a wrapper around tokio::net::UdpSocket that implements the NtpUdpSocket trait from sntpc. This separation allows:

  • Independent versioning: Update tokio without requiring sntpc core updates
  • Version flexibility: Works with any tokio 1.x version (>=1, <2)
  • Clean separation: Core SNTP protocol logic remains independent of async runtime
  • Future compatibility: When tokio 2.x releases, only this adapter needs updating

Usage

Add this to your Cargo.toml:

[dependencies]
sntpc = "0.8"
sntpc-net-tokio = "1"
tokio = { version = "1", features = ["net", "rt"] }

Example

use sntpc::{get_time, NtpContext, StdTimestampGen};
use sntpc_net_tokio::UdpSocketWrapper;
use tokio::net::UdpSocket;

#[tokio::main]
async fn main() {
    let socket = UdpSocket::bind("0.0.0.0:0").await.expect("Socket creation");
    let socket = UdpSocketWrapper::from(socket);
    let context = NtpContext::new(StdTimestampGen::default());

    let result = get_time("pool.ntp.org:123".parse().unwrap(), &socket, context).await;
    println!("Time: {:?}", result);
}

For complete examples, see the sntpc examples.

Compatibility

  • sntpc: 0.8.x
  • tokio: 1.x (any version >= 1.0, < 2.0)

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this codebase by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Commit count: 434

cargo fmt