Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Abort Asynchronous Socket Connect
Visual Basic example code showing how abort an asynchronous TCP socket connect. ' Demonstrates how to begin an asynchronous TCP/IP socket connection and
' then abort prior to completion.
' Create a Chilkat Socket object and unlock.
Set socket = New ChilkatSocket
success = socket.UnlockComponent("Anything for 30-day trial")
If (success = 0) Then
MsgBox "Failed to unlock component"
Exit Sub
End If
Dim hostname As String
hostname = "www.chilkatsoft.com"
' There is nothing listening at this port, so the connect will certainly
' timeout and fail -- unless it is aborted prior to timing out.
port = 132
' Wait a maximum of 10 seconds (10000 milliseconds)
maxWaitMs = 10000
' Begin an asynchronous TCP socket connect
success = socket.AsyncConnectStart(hostname, port, maxWaitMs)
If (success = 0) Then
MsgBox socket.LastErrorText
Exit Sub
End If
' Your program may now continue while the connect is proceeding in a
' background thread.
' You may abort the background thread at any point by calling AsyncConnectAbort.
' This example aborts after 1 second
socket.SleepMs 1000
socket.AsyncConnectAbort
' Wait for the connect to complete, fail, or abort.
Do
DoEvents
socket.SleepMs 10
Loop Until (socket.AsyncConnectFinished = 1)
' You may check the completion status by:
If (socket.AsyncConnectFinished = 1) Then
MsgBox "Background TCP connect thread is finished"
' If finished, you may check the success/failure status:
If (socket.AsyncConnectSuccess = 1) Then
MsgBox "TCP socket connected!"
Else
' if not successful, the error log is available in AsyncConnectLog:
MsgBox socket.AsyncConnectLog
End If
Else
MsgBox "Background connect thread is still running"
End If
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.