See Also

Dns Class  | Dns Members

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Language

Visual Basic

C#

C++

C++/CLI

Show All

host
The host name to resolve.
state
User state information.
See Also Languages PowerTCP SSL Sockets for .NET

BeginGetHost Method

Dart.PowerTCP.SslSockets Namespace > Dns Class : BeginGetHost Method

Asynchronously resolve a host name to a dot address or a dot address to a host name.

[Visual Basic]
<DescriptionAttribute("Begin an asynchronous name or IP address resolution.")> Public Function BeginGetHost( _    ByVal host As String, _    ByVal state As Object _ ) As IAsyncResult
[C#]
[DescriptionAttribute("Begin an asynchronous name or IP address resolution.")] public IAsyncResult BeginGetHost(    string host,    object state );
[C++]
[DescriptionAttribute("Begin an asynchronous name or IP address resolution.")] public: IAsyncResult* BeginGetHost(    string* host,    Object* state )
[C++/CLI]
[DescriptionAttribute("Begin an asynchronous name or IP address resolution.")] public: IAsyncResult^ BeginGetHost(    String^ host,    Object^ state )

Parameters

host
The host name to resolve.
state
User state information.

Return Type

An IAsyncResult that represents the asynchronous operation, which could still be pending.

Exceptions

ExceptionDescription
SocketExceptionNo DNS server was specified.
InvalidOperationExceptionBeginXXX method used without providing an EndXXX event handler.

Remarks

This method provides both asynchronous forward lookup (resolve a host name to an address) and asynchronous reverse lookup (resolve an address to a host name). When the lookup completes, the EndGetHost event is raised. Made available in this event is a DnsEventArgs which describes the response from the DNS server.

When host is a DNS-style host name associated with multiple IP addresses, only the first IP address that resolves to that host name is returned.

To resolve an email address asynchronously, use BeginGetMailHosts. To resolve a host name or a dot address synchronously, use GetHost.

Example

The following example demonstrates using the Dns control to asynchronously resolve a domain name.

[Visual Basic] 

Private Sub AsynchResolveTest()
   Dns1.Server = "206.64.128.5"
   Dns1.BeginGetHost("www.dart.com", Nothing)
End Sub

Private Sub Dns1_EndGetHost(ByVal sender As Object, ByVal e As DnsEventArgs) Handles Dns1.EndGetHost
   ' Check for any exceptions that occurred
   If e.Exception Is Nothing Then
      DisplayResult(e.Host)
   End If
End Sub

Private Sub DisplayResult(ByVal result As System.Net.IPHostEntry)
   ' Display host name
   Debug.WriteLine("Host name: " + result.HostName)

   ' Display addresses, if any
   Dim add As System.Net.IPAddress
   For Each add In result.AddressList
      Debug.WriteLine("Address: " + add.ToString())
   Next

   ' Display aliases, if any
   Dim s As String
   For Each s In result.Aliases
      Debug.WriteLine("Aliases: " + s)
   Next
End Sub

[C#] 


private void AsynchResolveTest()
{
  dns1.Server =
"206.64.128.5";
  dns1.BeginGetHost(
"www.dart.com", null);
}

private void dns1_EndGetHost(object sender, DnsEventArgs e)
{
  
// Check for any exceptions that occurred
  
if(e.Exception == null)
  {
     DisplayResult(e.Host);
  }
}

private void DisplayResult(System.Net.IPHostEntry result)
{
  
// Display host name
  
Debug.WriteLine("Host name: " + result.HostName);

  
// Display addresses, if any
  
foreach(System.Net.IPAddress add in result.AddressList)
     Debug.WriteLine(
"Address: " + add.ToString());

  
// Display aliases, if any
  
foreach(string s in result.Aliases)
     Debug.WriteLine(
"Aliases: " + s);
}
                

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Dns Class  | Dns Members


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.