'測試連線函式(VB)
Imports System.Net.NetworkInformation
Public Function IsHostAlive(ByVal hostNameOrAddress As String) As Boolean
Try
Dim pingSender As New Ping()
Dim reply As PingReply = pingSender.Send(hostNameOrAddress)
If reply.Status = IPStatus.Success Then
Return True
Else
Return False
End If
Catch ex As Exception
Return False
End Try
End Function
'函式用法
If IsHostAlive("192.168.0.1") Then
' 連線成功
Else
' 連線失敗
End If
製作程序讀取產線設備電腦資料,轉存至伺服器用。避免因連線中斷造成系統讀取迴圈異常耗時。
請先 登入 以發表留言。