'測試連線函式(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

製作程序讀取產線設備電腦資料,轉存至伺服器用。避免因連線中斷造成系統讀取迴圈異常耗時。

創作者介紹
創作者 Working Notes-My Work Diary 的頭像
laizhucheng

Working Notes-My Work Diary

laizhucheng 發表在 痞客邦 留言(0) 人氣( 2 )