apple/swift-ntp
Swift NTP library using Swift NIO. Provides an NTPClient.
Overview
This library provides a client that partially implements NTP v3 (RFC 1305). It also comes with limited support for NTP v4 (RFC 5905).
Library Structure
This repository contains two main library products:
NTPClient: Provides the high-levelNTPClient. This is intended for consumption by other projects.
NTP: (packagelevel) Contains the core NTP protocol logic, packet parsing/serialization, and data structures. It is currently not publicly accessible.
π» Examples
Examples can be found in the Snippets directory.
// Instantiate the NTP Client
let ntp = NTPClient(
config: NTPClient.Config(
version: .v4 // Ensure the use of NTPv4.
),
server: "time.apple.com", // Configure the time source.
)
// Asynchronously query the time source
let response = try await ntp.query(timeout: .seconds(2))
// Get clock offset.
print("offset = \(response.offset)")π Contributing
Contributions are welcome! Take a look at CONTRIBUTING.md to learn how.
π Security
Security issues should be reported via the process in SECURITY.md.
πͺͺ License
The project is licensed under Apache 2.0 license repeated in LICENSE.txt.
Package Metadata
Repository: apple/swift-ntp
Stars: 98
Forks: 11
Open issues: 0
Default branch: main
Primary language: swift
License: Apache-2.0
README: README.md