Visual Basic Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CUnicode C++Unicode CMFCDelphi DLLDelphi ActiveXFoxProJavaPerlPHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

VB Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
Email
FTP
HTML Conversion
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SFTP
SMTP
Socket
Spider
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
DH Key Exchange
DSA
FileAccess
RSS
Atom
Self-Extractor
Service
Bzip2
PPMD
Deflate
LZW


VB Strings
VB Byte Array

 

 

 

 

 

 

 

Abort Asynchronous Socket Connect

Download Chilkat Socket ActiveX

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
     
    ' To use SSL/TLS, set ssl = 1
    ssl = 0

    ' Begin an asynchronous TCP socket connect
    success = socket.AsyncConnectStart(hostname, port, ssl, 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


 

© 2000-2013 Chilkat Software, Inc. All Rights Reserved.