[][src]Struct rsntp::SntpClient

pub struct SntpClient { /* fields omitted */ }

Blocking SNTP client instance

This is the main entry point of the blocking API. It is an association between the local host and the remote server and can be reused, i.e. multiple synchronization can be executed with a single instance.

Methods

impl SntpClient[src]

pub fn new(server_address: &str) -> Result<SntpClient, Error>[src]

Creates a new instance.

The parameter is the server DNS name or IP addresss. It uses the default SNTP UDP port (123)

Example

use rsntp::SntpClient;

let client = SntpClient::new("pool.ntp.org").unwrap();

pub fn with_socket_addr<T: ToSocketAddrs>(
    socket_addr: T
) -> Result<SntpClient, Error>
[src]

Creates a new instance for the given socket addres.

Example

use rsntp::SntpClient;

let socket_addr = ("pool.ntp.org", 123);
let client = SntpClient::with_socket_addr(socket_addr).unwrap();

pub fn synchronize(
    &self
) -> Result<SynchronizationResult, SynchroniztationError>
[src]

Synchronize with the server

It sends a request to the server, waits for the reply and processes that reply. This is a blocking call and can block for quite long time. After sending the request it waits for a timeout and if no reply is received then an error is returned.

Example

use rsntp::SntpClient;

let socket_addr = ("pool.ntp.org", 123);
let client = SntpClient::with_socket_addr(socket_addr).unwrap();
let result = client.synchronize();

pub fn set_timeout(&mut self, timeout: Duration)[src]

Sets synchronization timeout

This sets the amount of time which the client waits for reply after the request has been sent. Default is 3 seconds.

Example

use rsntp::SntpClient;
use std::time::Duration;

let mut client = SntpClient::new("pool.ntp.org").unwrap();
client.set_timeout(Duration::from_secs(10));

Trait Implementations

impl Clone for SntpClient[src]

impl Debug for SntpClient[src]

impl Hash for SntpClient[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.