Glossary Item Box

PowerTCP SSL Sockets for .NET

Performing A Trace Route 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 performing a trace route operation asynchronously using the BeginSend method.

 

To perform an asynchronous trace route operation:

  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 trace route operation.

    [Visual Basic, C#]

    [C#]
    // Set all hops and echoes to be synchronous
    trace1.HopType = HopType.SynchHops;
    
    // Begin the trace.
    trace1.BeginSend("www.dart.com", null);
    
    [Visual Basic]
    ' Set all hops and echoes to be synchronous
    Trace1.HopType = SynchHops
    
    ' Begin the trace.
    Trace1.BeginSend("www.dart.com", Nothing)
    
  4. The trace route operation will cause the Hop event to be raised whenever data is received from a new hop. Implement this event.

    [Visual Basic, C#]

    [C#]
    private void trace1_Hop(object sender, Dart.PowerTCP.SslSockets.HopEventArgs e)
    {
       // Check for any exceptions
       if(e.Exception == null)
       {
          // Display information about the hop
          Debug.WriteLine("Time-to-live for the hop: " + e.Result.TTL);
          Debug.WriteLine("Remote address: " + e.Result.RemoteAddress);
    
          // Now display info about each of the three echoes
          Debug.WriteLine("Response times for this hop");
          foreach(EchoResult er in e.Result.Echoes)
             Debug.WriteLine(er.ResponseTime);
       }
    }
    
    [Visual Basic]
    Private Sub Trace1_Hop(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.HopEventArgs) Handles Trace1.Hop   
       
       ' Check for any exceptions
       If e.Exception Is Nothing Then
          ' Display information about the hop
          Debug.WriteLine("Time-to-live for the hop: " & e.Result.TTL)
          Debug.WriteLine("Remote address: " & e.Result.RemoteAddress)
    
          ' Now display info about each of the three echoes
          Debug.WriteLine("Response times for this hop")
          Dim er As EchoResult
          For Each er In e.Result.Echoes
             Debug.WriteLine(er.ResponseTime)
          Next
       End If
    End Sub
    
  5. When the trace operation completes, the EndSend event will be raised. Any actions that need to be performed after the operation is complete should be put here. For this example, some data is simply displayed. Your entire EndSend event should look something like the following.

    [Visual Basic, C#]

    [C#]
    private void trace1_EndSend(object sender, Dart.PowerTCP.SslSockets.TraceEventArgs e)
    {
       // Check for any exceptions
       if(e.Exception == null)
          // Trace operation completed successfully, display info.
          Debug.WriteLine("Total hops: " + e.Result.Hops.Length);   
       else
          Debug.WriteLine("Exception: " + e.Exception.Message);
    }
    
    [Visual Basic]
    Private Sub Trace1_EndSend(ByVal sender As Object, ByVal e As Dart.PowerTCP.SslSockets.TraceEventArgs) Handles Trace1.EndSend
       ' Check for any exceptions
       If e.Exception Is Nothing Then
          ' Trace operation is complete, display info.
          Debug.WriteLine("Total hops: " & e.Result.Hops.Length)
       Else
          Debug.WriteLine("Exception: " & e.Exception.Message)
       End If
    End Sub
    
  6. 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.