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
options
are anEnumerable.t()
with these keys:auto_start
is aboolean()
defaults totrue
retreive_every
is anon_neg_integer()
defaults to86400000
every 24 hourhost
isbinary() | charlist()
defualts to'pool.ntp.org'
port
is annon_neg_integer()
between0..65535
defualts to123
timeout
is annon_neg_integer()
defualts to:infinity
resolve_reference
is 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}
options
anEnumerable.t()
with these keys:host
isbinary() | charlist()
defualts to'pool.ntp.org'
port
is annon_neg_integer()
between0..65535
defualts to123
timeout
is annon_neg_integer()
defualts to:infinity
resolve_reference
is 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"]}