C# Класс Yort.Ntp.NtpClient

Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
BeginRequestTime ( ) : void

Asynchronously requests a time from the NTP server specified in the constructor. When a time is received the TimeReceived event is raised with the result, otherwise the ErrorOccurred event should be raised containing details of the failure.

Note, events raised by this class may not (and probably will not) occur on the same thread that called this method. If the event handlers call UI components, dispatched invoke may be required.

This method may throw exceptions (most likely a NtpNetworkException if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.

NtpClient ( ) : System

Default constructor. Uses the KnownNtpServers.TimeANist server as a default.

NtpClient ( string serverAddress ) : System

Full constructor.

RequestTimeAsync ( ) : System.Threading.Tasks.Task

Returns an awaitable task whose result is the current time from the NTP server specified in the constructor.

This method may throw exceptions (most likely a NtpNetworkException if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.

Защищенные методы

Метод Описание
OnErrorOccurred ( Exception exception ) : void

Raises the ErrorOccurred event.

This event may be raised on a different thread than called the BeginRequestTime method. If the event handler refers to UI, COM or other components that require thread affinity then dispatched invoke may be required.

OnTimeReceived ( System.DateTime time ) : void

Raises the TimeReceived event.

This event may be raised on a different thread than called the BeginRequestTime method. If the event handler refers to UI, COM or other components that require thread affinity then dispatched invoke may be required.

The time returned is a UTC time.

Приватные методы

Метод Описание
ConvertBufferToCurrentTime ( byte buffer ) : void
ExceptionToNtpNetworkException ( Exception ex ) : NtpNetworkException
ExecuteWithSuppressedExceptions ( System.Action work ) : void
NtpNetworkExceptionFromSocketArgs ( SocketAsyncEventArgs e ) : NtpNetworkException
OnErrorOccurredAndDisposeSocket ( Exception exception, System.Net.Socket socket ) : void
SendTimeRequest ( ) : void
Socket_Completed_ProcessResult ( object sender, SocketAsyncEventArgs e ) : void
Socket_Completed_Receive ( Windows sender, Windows args ) : void
Socket_Completed_Receive ( object sender, SocketAsyncEventArgs e ) : void
Socket_Completed_SendAgain ( object sender, SocketAsyncEventArgs e ) : void
sArgs_Completed ( object sender, SocketAsyncEventArgs e ) : void

Описание методов

BeginRequestTime() публичный Метод

Asynchronously requests a time from the NTP server specified in the constructor. When a time is received the TimeReceived event is raised with the result, otherwise the ErrorOccurred event should be raised containing details of the failure.

Note, events raised by this class may not (and probably will not) occur on the same thread that called this method. If the event handlers call UI components, dispatched invoke may be required.

This method may throw exceptions (most likely a NtpNetworkException if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.

public BeginRequestTime ( ) : void
Результат void

NtpClient() публичный Метод

Default constructor. Uses the KnownNtpServers.TimeANist server as a default.
public NtpClient ( ) : System
Результат System

NtpClient() публичный Метод

Full constructor.
public NtpClient ( string serverAddress ) : System
serverAddress string the name or address the NTP server to be used.
Результат System

OnErrorOccurred() защищенный Метод

Raises the ErrorOccurred event.

This event may be raised on a different thread than called the BeginRequestTime method. If the event handler refers to UI, COM or other components that require thread affinity then dispatched invoke may be required.

protected OnErrorOccurred ( Exception exception ) : void
exception System.Exception A derived instance describing the error.
Результат void

OnTimeReceived() защищенный Метод

Raises the TimeReceived event.

This event may be raised on a different thread than called the BeginRequestTime method. If the event handler refers to UI, COM or other components that require thread affinity then dispatched invoke may be required.

The time returned is a UTC time.

protected OnTimeReceived ( System.DateTime time ) : void
time System.DateTime The date and time received from the NTP server.
Результат void

RequestTimeAsync() публичный Метод

Returns an awaitable task whose result is the current time from the NTP server specified in the constructor.

This method may throw exceptions (most likely a NtpNetworkException if an error occurs trying to connect/bind to the network endpoint. Exception handling in client code is recommended.

public RequestTimeAsync ( ) : System.Threading.Tasks.Task
Результат System.Threading.Tasks.Task