The following example demonstrates how to perform a simple TraceRoute to the remote host, www.yahoo.com, using the event driven model.
[C#]
using System; using aspNetTraceRoute; namespace ConsoleApplication1 { class Class1 { [STAThread] static void Main(string[] args) { TraceRouteClient client = new TraceRouteClient(); client.ReceivedReply += new ReceivedReplyEventHandler( Client_OnReply ); client.TraceRoute( "www.yahoo.com" ); Console.WriteLine( "done."); Console.ReadLine(); } static void Client_OnReply( object sender, ReceivedReplyEventArgs e ) { //write out the response Console.WriteLine( e.Packet.ToString() ); //if we wanted to cancel the traceroute, uncomment the following line //e.Cancel = true; } } }
[VB.NET]
Imports System Imports aspNetTraceRoute Module Module1 Sub Main() Dim client As New TraceRouteClient() AddHandler client.ReceivedReply, AddressOf Client_OnReply client.TraceRoute("www.yahoo.com") Console.WriteLine("done.") Console.ReadLine() End Sub Sub Client_OnReply(ByVal sender As Object, ByVal e As ReceivedReplyEventArgs) 'write out the response Console.WriteLine(e.Packet.ToString()) 'if we want to canel the traceroute, uncomment the following line 'e.Cancel = True End Sub End Module
Copyright 2003 - Contact: Webmaster