Chilkat HOME Android™ ASP Visual Basic VB.NET C# iOS (IPhone) Objective-C C++ C Unicode C++ Unicode C MFC Delphi DLL Delphi ActiveX FoxPro Java Perl PHP Extension PHP ActiveX Python PowerShell Ruby SQL Server VBScript
Asynch Socket Connect - Establish 10 TCP/IP Connections Simultaneously
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.