C# 클래스 Yort.Ntp.NtpClient

파일 보기 프로젝트 열기: Yortw/Yort.Ntp 1 사용 예제들

공개 메소드들

메소드 설명
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