TcpClient使非同步連接

Dim MyTcpClient As New TcpClient()
Dim MyResult As IAsyncResult = MyTcpClient.BeginConnect(YourTargetIP, YourTargetPort, Nothing, Nothing)
MyResult.AsyncWaitHandle.WaitOne(3000, True) '等三秒
If Not MyResult.IsCompleted Then
MyTcpClient.Close()
ElseIf MyTcpClient.Connected = True Then
MyTcpClient.Close()
End If

留言

這個網誌中的熱門文章

使用VB讀取健保卡基本資料

使用VB讀取自然人評証卡號