NSDNTP メンバ
Network Time Protocolを使用して、NTPサーバーから時刻を取得します。
●コンストラクタ
名前 引数 説明 NSDNTP なし NSDNTPを初期化します。 ( String ) 接続サーバー名を指定してNSDNTPを初期化します。
●プロパティの一覧
名前 説明 NTPServerName 接続するNTPサーバーの名前を設定します。 PortNo 接続ポート番号を設定します。 SendTimeOut 送信時のタイムアウトを設定します。 ReceiveTimeout 受信時のタイムアウトを設定します。 RetryCount タイムアップなどのエラー発生時にリトライする回数を設定します。
●メソッドの一覧
名前 引数 戻り値 説明 Dispose なし なし リソースの解放を行います。 GetStdDateTime ( DateTime ) Boolean型 NTPサーバーから時刻を取得します。
構文:Public Sub New()
使用法:Dim Cls_NTP As New NSDNTP
引数:なし。
使用例:
Public Class Form1 Dim Cls_NTP As New NSDNTP : End Class
構文:Public Sub New( String )
使用法:Dim Cls_NTP As New NSDNTP( ServerName )
引数:なし。
使用例:
Public Class Form1 Dim Cls_NTP As New NSDNTP("サーバー名") : End Class
●NSDNTPプロパティの説明
名前:NTPServerName
構文:Public Property NTPServerName() As String
機能:接続するNTPサーバーの名前を設定します。
Set値:接続するNTPサーバーの名前をセットします。
Get値:接続するNTPサーバーの名前を取得します。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP Cls_NTP.NTPServerName = "" ' <- 接続サーバー名. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
名前:PortNo
構文:Public Property PortNo() As Integer
機能:接続ポート番号を設定します。
Set値:接続ポート番号をセットします。
Get値:接続ポート番号を取得します。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Cls_NTP.PortNo = 123 Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
名前:SendTimeOut
構文:Public Property SendTimeOut() As Integer
機能:送信時のタイムアウトを設定します(単位:ミリ秒)。
Set値:送信時のタイムアウトを設定します。
Get値:送信時のタイムアウトを取得します。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Cls_NTP.SendTimeOut = 1000 ' 送信時のタイムアウトを1秒に設定. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
名前:ReceiveTimeout
構文:Public Property ReceiveTimeout() As Integer
機能:受信時のタイムアウトを設定します(単位:ミリ秒)。
Set値:受信時のタイムアウトを設定します。
Get値:受信時のタイムアウトを取得します。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Cls_NTP.ReceiveTimeout = 1000 ' 受信時のタイムアウトを1秒に設定. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
名前:RetryCount
構文:Public Property RetryCount() As Integer
機能:タイムアップなどのエラー発生時にリトライする回数を設定します。
Set値:リトライする回数を設定します。
Get値:リトライする回数を取得します。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Cls_NTP.RetryCount = 5 ' リトライ数を5回に設定. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
●NSDNTPメソッドの説明
名前:Dispose
構文:Public Overridable Sub Dispose() Implements IDisposable.Dispose 機能:リソースを解放します。
※終了時に必ず呼び出します。
引数:なし。
戻り値:なし。
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Dim Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If Cls_NTP.Dispose() Catch ex As Exception End Try End Sub End Class
名前:GetStdDateTime
構文:Public Function GetStdDateTime( Date_Time ) As Boolean 機能:NTPサーバーから時刻を取得します。
引数:
名前 型 引数渡しの方法 説明 Date_Time DateTime 参照渡し(ByRef) サーバーの時刻を返します。 戻り値:Boolean
戻り値の説明:
True:成功 False:失敗
使用例:
Public Class Form1 Private Sub Button1_Click( sender As System.Object, _ e As System.EventArgs) Handles Button1.Click Try Using Cls_NTP As New NSDNTP("") ' <- 接続サーバー名を指定します. Dim Date_Time As DateTime = Nothing If Cls_NTP.GetStdDateTime(Date_Time) Then MsgBox("現在の時刻:" & Date_Time.ToString()) Else MsgBox("サーバーから時刻を受信できません。") End If End Using Catch ex As Exception End Try End Sub End Class
Copyright (C) 2013 Nihon System Developer Corp. All Rights Reserved.