Visual Basic Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP 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

 

 

 

 

 

 

 

Asynchronously Accepting Socket Connections

Download Chilkat Socket ActiveX

Demonstrates how to asynchronously accept a TCP socket connection using the Chilkat Socket ActiveX component.

Private Sub AsyncAccept_Click()

    ' VB example showing how to listen on a port and accept the next
    ' TCP connection in a background thread.
    Dim accSocket As New ChilkatSocket
    Dim connectedSocket As ChilkatSocket
    
    success = accSocket.UnlockComponent("Anything for 30-day trial")
    If (success = 0) Then
        MsgBox "Failed to unlock component"
        Exit Sub
    End If
    
    ' Bind the TCP socket to a port and configure it for listening.
    ' This call does not block.
    port = 132
    backlog = 25
    success = accSocket.BindAndListen(port, backlog)
    If (success = 0) Then
        MsgBox accSocket.LastErrorText
        Exit Sub
    End If
    
    ' Setting maxWaitMs = 0 indicates that there is no timeout.
    maxWaitMs = 0
        
    ' Wait for an incoming connection on a background thread.
    success = accSocket.AsyncAcceptStart(maxWaitMs)
    
    ' You may abort the background thread at any point by calling AsyncAcceptAbort.
    ' This example aborts after 1 second
    'accSocket.SleepMs 1000
    'accSocket.AsyncAcceptAbort
    
    ' Wait for the connect to complete, fail, or abort.
    Do
        DoEvents
        accSocket.SleepMs 10
    Loop Until (accSocket.AsyncAcceptFinished = 1)

    ' You may check the completion status by:
    If (accSocket.AsyncAcceptFinished = 1) Then
    
        MsgBox "Background TCP accept thread is finished"
        
        ' If finished, you may check the success/failure status:
        If (accSocket.AsyncAcceptSuccess = 1) Then
            MsgBox "TCP socket connection accepted!"
            
            ' The socket object can be retrieved by calling AsyncAcceptSocket()
            ' NOTE: After retrieving the connectedSocket, the next call to AsyncAcceptSocket
            ' will return Nothing.  The connected socket can only be retrieved once.
            Set connectedSocket = accSocket.AsyncAcceptSocket()
            
            ' Your program may now send and receive messages on connectedSocket...
            
        Else
            ' if not successful, the error log is available in AsyncAcceptLog:
            MsgBox accSocket.AsyncAcceptLog
        End If
    Else
         MsgBox "Background accept thread is still running"
    End If

    
    
    
End Sub


 

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