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
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
留言