NtpServer Class
An NTP server that responds to NTP time queries. Supports NTPv3 and NTPv4, mirroring the version sent by the client.
public sealed class NtpServer : IDisposableRemarks
The server answers from NtpServerOptions.TimeProvider and does not discipline that clock, so it is only as accurate as the machine it runs on. It implements no authentication: neither NTS (RFC 8915) nor symmetric keys.
- Implements
Constructors
| Name | Description |
|---|---|
| NtpServer(NtpServerOptions?) | Initializes a new instance of the NtpServer class. |
NtpServer(NtpServerOptions?)
NtpServer.csInitializes a new instance of the NtpServer class.
public NtpServer(NtpServerOptions? options = null)Parameters
optionsNtpServerOptions?- Optional server configuration.
Properties
| Name | Description |
|---|---|
| Completion | Gets a task that completes when the listen loop stops, either because the server was disposed or the start token was cancelled, or faulted because the loop hit an unrecoverable error. |
| Port | Gets the port the server is listening on. Only valid after NtpServer.StartAsync has been called. |
Completion
NtpServer.csGets a task that completes when the listen loop stops, either because the server was disposed or the start token was cancelled, or faulted because the loop hit an unrecoverable error.
public Task Completion { get; }Port
NtpServer.csGets the port the server is listening on. Only valid after NtpServer.StartAsync has been called.
public int Port { get; }Property value
Methods
| Name | Description |
|---|---|
| Dispose() | Releases the resources used by this instance and stops listening. |
| StartAsync(CancellationToken) | Starts the NTP server and begins listening for client requests. |
Dispose()
NtpServer.csReleases the resources used by this instance and stops listening.
public void Dispose()StartAsync(CancellationToken)
NtpServer.csStarts the NTP server and begins listening for client requests.
public Task StartAsync(CancellationToken cancellationToken = default)Parameters
cancellationTokenCancellationToken- A cancellation token that stops the server when cancelled.
Returns
Task A task that completes when the server has started listening.
Exceptions
InvalidOperationException- The server has already been started.