SNTP (SNTP v0.2.2) View Source
SNTP v4 client RFC4330 for Elixir
Link to this section Summary
Functions
Returns the system time in milliseconds.
If the SNTP.Retriever is running then it will return the adjusted system time.
Returns the latest retrieved offset from the SNTP.Retriever
Starts the SNTP.Retriever
Stops the SNTP.Retriever
Sends a new NTP request on an SNTP.Socket and gracefully closes the socket.
Returns {:ok, %SNTP.Timestamp{}} or {:error, reason}
Link to this section Functions
Specs
now() :: pos_integer()
Returns the system time in milliseconds.
If the SNTP.Retriever is running then it will return the adjusted system time.
Examples
iex> SNTP.now()
System.system_time(1000) Specs
offset() :: {:ok, number()} | {:error, {Exception.t(), binary()}}
Returns the latest retrieved offset from the SNTP.Retriever
Examples
iex> SNTP.offset()
{:ok, 12}
iex> SNTP.offset()
{:error, {SNTP.RetrieverError, "SNTP Retriever is not started"}} Specs
start(Enumerable.t()) :: {:ok, pid()}
Starts the SNTP.Retriever
optionsare anEnumerable.t()with these keys:auto_startis aboolean()defaults totrueretreive_everyis anon_neg_integer()defaults to86400000every 24 hourhostisbinary() | charlist()defualts to'pool.ntp.org'portis annon_neg_integer()between0..65535defualts to123timeoutis annon_neg_integer()defualts to:infinityresolve_referenceis aboolean()defualts tofalse
Examples
iex> SNTP.start()
{:ok, #PID<0.000.0>} Specs
stop(pid()) :: :ok
Stops the SNTP.Retriever
Examples
iex> SNTP.stop()
:ok Specs
time(Enumerable.t()) :: {:ok, integer()} | {:error, term()}
Sends a new NTP request on an SNTP.Socket and gracefully closes the socket.
Returns {:ok, %SNTP.Timestamp{}} or {:error, reason}
optionsanEnumerable.t()with these keys:hostisbinary() | charlist()defualts to'pool.ntp.org'portis annon_neg_integer()between0..65535defualts to123timeoutis annon_neg_integer()defualts to:infinityresolve_referenceis aboolean()defualts tofalse
Examples
iex> {:ok, timestamp} = SNTP.time()
iex> timestamp.is_valid?
true
iex> SNTP.time(host: 'ntp.exnet.com', port: 123, timeout: 100))
{:error, [timeout: "Server Timeout after 100"]}