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
DNS Lookup with Heartbeat Event Callbacks and Abort Capability
DNS lookup Visual Basic example. This example demonstrates how to do a DNS lookup with event callbacks. The DNS lookup may be aborted while in progress. Dim WithEvents socket As ChilkatSocket Private bAbortDns As Boolean ' This called when an "Abort" button in the user interface ' is pressed. Private Sub AbortButton_Click() bAbortDns = True End Sub ' Do a DNS hostname lookup. ' Translates an IP hostname (such as "www.chilkatsoft.com") ' into an IP address string (such as "168.144.70.227") Private Sub DnsButton_Click() bAbortDns = False ProgressBar1.Value = 0 ' 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 ' You may wish to test the code with both valid and invalid hostnames. ' hostname = "www.123abc32893489.com" hostname = "www.chilkatsoft.com" ' Uncomment this line to simulate a long DNS lookup time to allow you ' to test your application's behavior while a DNS lookup is in progress. ' (units are in milliseconds) ' socket.DebugDnsDelay = 3000 ' Set our hearbeat event interval time in milliseconds: socket.HeartbeatMs = 200 ' The total DNS lookup timeout (in milliseconds) is passed as an argument totalTimeoutMs = 10000 Dim ipAddr As String ipAddr = socket.DnsLookup(hostname, totalTimeoutMs) If Len(ipAddr) = 0 Then MsgBox socket.LastErrorText Else MsgBox hostname & " = " & ipAddr End If End Sub ' The heartbeat event is called when a blocking call is in progress, ' such as a DNS lookup... ' 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 DNS lookup is proceeding... newValue = ProgressBar1.Value + 5 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 bAbortDns Then ' Setting abort = 1 causes the DNS lookup to abort. abort = 1 Else ' Setting abort = 0 causes the DNS lookup to continue waiting. abort = 0 End If End Sub
|
© 2000-2013 Chilkat Software, Inc. All Rights Reserved.