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

 

 

 

 

 

 

 

Accept Connection Synchronously with Heartbeat Events and Abort

Download Chilkat Socket ActiveX

Demonstrates how to listen at a port and accept the next incoming TCP socket connection.

Dim WithEvents socket As ChilkatSocket
Private bAbortAccept As Boolean

Private Sub AbortButton_Click()

    bAbortAccept = True

End Sub

' Demonstrates how to listen and wait for incoming TCP connections
' at a port.  The AcceptNextConnection call is synchronous.  Heartbeat
' events are periodically fired to allow the application to abort waiting
' for a connection before the max timeout.  The Chilkat Socket ActiveX
' also provides methods for asynchronous accept.
Private Sub AcceptButton_Click()

    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
    
    ' Bind the TCP socket to a port and configure it for listening.
    Port = 132
    backlog = 25
    success = socket.BindAndListen(Port, backlog)
    If (success = 0) Then
        MsgBox socket.LastErrorText
        Exit Sub
    End If
    
    ' Accept the next incoming connection.
    ' Wait a maximum of 10 seconds
    maxWaitMs = 10000
    
    ' Make a heartbeat callback every .2 seconds
    socket.HeartbeatMs = 200
    
    ' Make a synchronous call to accept the next incoming connection.
    Dim socket2 As ChilkatSocket
    Set socket2 = socket.AcceptNextConnection(maxWaitMs)
    If socket2 Is Nothing Then
        MsgBox socket.LastErrorText
        Exit Sub
    End If
        
    List1.AddItem ("connected!")

End Sub

' The heartbeat event is called when a blocking call is in progress,
' such as an AcceptNextConnection...

' Each Chilkat Socket object has a unique objectID
' The object ID is passed to the heartbeat event to allow
' your application to know which socket object fired the event.
Private Sub socket_Heartbeat(ByVal objectID As Long, abort As Long)

    ' Indicate that the AcceptNextConnection is waiting...
    newValue = ProgressBar1.Value + 1
    If newValue <= ProgressBar1.Max Then
        ProgressBar1.Value = newValue
    End If
        
    ' Call DoEvents to allow the application to process user-interface events.
    DoEvents
    
    ' Did the Abort button get pressed?
    If bAbortAccept Then
        ' Setting abort = 1 causes the AcceptNextConnection to abort.
        abort = 1
    Else
        ' Setting abort = 0 causes the AcceptNextConnection to continue waiting.
        abort = 0
    End If

End Sub

 

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