| Crates.io | sntpc-net-tokio |
| lib.rs | sntpc-net-tokio |
| version | 1.0.1 |
| created_at | 2026-01-08 11:30:11.926872+00 |
| updated_at | 2026-01-08 13:16:05.456021+00 |
| description | Tokio socket wrapper for sntpc library |
| homepage | |
| repository | https://github.com/vpetrigo/sntpc |
| max_upload_size | |
| id | 2030014 |
| size | 25,228 |
Tokio async runtime UDP socket adapter for the sntpc SNTP client library.
This crate provides a wrapper around tokio::net::UdpSocket that implements the NtpUdpSocket trait from sntpc. This
separation allows:
sntpc core updates>=1, <2)Add this to your Cargo.toml:
[dependencies]
sntpc = "0.8"
sntpc-net-tokio = "1"
tokio = { version = "1", features = ["net", "rt"] }
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.