Glossary Item Box

PowerTCP SSL Sockets for .NET

Pinging Asynchronously

Asynchronous operations are useful because they occur without waiting for the action to complete before executing the next line of code. Such a technique is useful when an operation is time consuming and other code needs to execute without waiting for the operation to complete. The following example demonstrates pinging a host asynchronously using the BeginSend method.

 

To ping a host asynchronously.

  1. Add a button to the form.
  2. In this example, the BeginSend method will be used. The EndSend event will be raised when this operation has completed. "Wire-up" the EndSend event.
  3. Begin the asynchronous ping operation.

    [Visual Basic, C#]

    [C#]
    // Begin the ping.
    ping1.BeginSend("www.dart.com", null);
    
    [Visual Basic]
    ' Begin the ping.
    Ping1.BeginSend("www.dart.com", Nothing)
    
  4. When the EndSend event is raised, take some action. In this example, the data is simply displayed. Your entire EndSend event should look something like the following.

    [Visual Basic, C#]

    [C#]
    private void ping1_EndSend(object sender, Dart.PowerTCP.SslSockets.PingEventArgs e)
    {
       if(e.Exception == null)
       {
          // EchoResult er describes the ping. Display properties of the EchoResult.
          Debug.WriteLine("Reply from " + e.Result.RemoteAddress);
          Debug.WriteLine("Bytes " + e.Result.Data.Length);
          Debug.WriteLine("Time " + e.Result.ResponseTime);
          Debug.WriteLine("TTL " + e.Result.TTL);
       }
       else
          Debug.WriteLine(e.Exception.Message);
    }
    
    [Visual Basic]
    Private Sub Ping1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.PingEventArgs) Handles Ping1.EndSend
       
       If Not e.Exception Is Nothing Then 
          ' EchoResult er describes the ping. Display properties of the EchoResult.
          Debug.WriteLine("Reply from " + e.Result.RemoteAddress)
          Debug.WriteLine("Bytes " + e.Result.Data.Length)
          Debug.WriteLine("Time " + e.Result.ResponseTime)
          Debug.WriteLine("TTL " + e.Result.TTL)
       Else
          Debug.WriteLine(e.Exception.Message)
       End If
    End Sub
    
  5. Compile and run the application.

 

In This Section

Resolving IP Addresses, Host Names and Email Addresses
Demonstrates how to resolve IP Addresses, host names and email addresses using the Dns component.
Resolving Asynchronously
Demonstrates how to use the Dns component to asynchronously resolve addresses.
Simple Pinging
Demonstrates how to ping a host.
Pinging Asynchronously
Demonstrates how to ping a host asynchronously.
Performing A Simple Trace Route Operation
Demonstrates how to trace a route to a host.
Performing A Trace Route Asynchronously
Demonstrates how to trace a route to a host asynchronously.

 

 


Send comments on this topic.

Documentation version 1.1.2.0.

© 2008 Dart Communications.  All rights reserved.