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

 

 

 

 

 

 

 

Asynch Socket Connect - Establish 10 TCP/IP Connections Simultaneously

Download Chilkat Socket ActiveX

Visual Basic sample code showing how to establish a TCP socket connection asynchronously. This example establishes 10 connections in parallel.

    ' Demonstrate asynchronous TCP/IP socket connect.
    ' This example establishes 10 TCP socket connections simultaneously.
    
    ' Create 10 ChilkatSocket objects
    Dim socketArray(9) As ChilkatSocket
    For i = 0 To 9
        Set socketArray(i) = New ChilkatSocket
    Next
    
    ' Only need to unlock once.
    success = socketArray(0).UnlockComponent("Anything for 30-day trial")
    If (success = 0) Then
        MsgBox "Failed to unlock component"
        Exit Sub
    End If
    
    Dim hostname(9) As String
    hostname(0) = "www.chilkatsoft.com"
    hostname(1) = "www.microsoft.com"
    hostname(2) = "www.intel.com"
    hostname(3) = "www.apple.com"
    hostname(4) = "www.tagtooga.com"
    hostname(5) = "www.ebay.com"
    hostname(6) = "www.nytimes.com"
    hostname(7) = "www.amazon.com"
    hostname(8) = "search.msn.com"
    hostname(9) = "www.a9.com"
    
    ' This example will make a connection with port 80 (the HTTP port)
    Port = 80
    
    ' Start 10 simultaneous connections
    ' Wait a maximum of 10 seconds for any one.
    maxWaitMs = 10000
    For i = 0 To 9
        success = socketArray(i).AsyncConnectStart(hostname(i), Port, maxWaitMs)
    Next
    
    ' Wait for the connections to complete.
    Do
        numComplete = 0
        
        ' Count how many have completed...
        For i = 0 To 9
            If (socketArray(i).AsyncConnectFinished = 1) Then
                numComplete = numComplete + 1
            End If
        Next
        
        ' Process application events while waiting...
        DoEvents
        
        ' For convenience, the ChilkatSocket component provides the SleepMs method
        ' Sleep for 1/10th of a second.
        socketArray(0).SleepMs 100
        
    Loop Until (numComplete > 9)
        
    ' Display the connection successes and failures
    For i = 0 To 9
        If (socketArray(i).AsyncConnectSuccess = 1) Then
            List1.AddItem hostname(i) & ": Success"
        Else
            List1.AddItem hostname(i) & ": FAILED"
        End If
    Next
    
    MsgBox "Done!"

 

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