Glossary Item Box
Ping is typically used to see if a host is reachable by sending an ICMP echo packet to a host and timing the response. As the following examples illustrate, this is quite easy to implement using the Ping component.
Example 1: Pinging with default settings.
This is the most standard usage example of the Ping component. Simply call Send, passing in the host name or IP address you wish to ping. The host will be pinged with 32 bytes of data. An EchoResult will be returned, describing the ping operation.
[C#] // Ping the host. EchoResult er = ping1.Send("www.dart.com"); // EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + er.RemoteAddress); Debug.WriteLine("Bytes " + er.Data.Length); Debug.WriteLine("Time " + er.ResponseTime); Debug.WriteLine("TTL " + er.TTL); [Visual Basic] ' Ping the host. Dim er as EchoResult = Ping1.Send("www.dart.com") ' EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + er.RemoteAddress) Debug.WriteLine("Bytes " + er.Data.Length) Debug.WriteLine("Time " + er.ResponseTime) Debug.WriteLine("TTL " + er.TTL)
Example 2: Pinging with specified settings.
You can also specify how the Ping operation takes place. For example, you can specify the data, the EchoResult.TTL, and the sequence number.
[C#] // Ping the host, specifying the data, TTL, sequence number, and local host. byte[] data = System.Text.Encoding.Default.GetBytes("*********"); EchoResult er = ping1.Send("www.dart.com", 100, 1, "192.168.0.83", data); // EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + er.RemoteAddress); Debug.WriteLine("Bytes " + er.Data.Length); Debug.WriteLine("Time " + er.ResponseTime); Debug.WriteLine("TTL " + er.TTL); [Visual Basic] ' Ping the host, specifying the data, TTL, sequence number, and local host. Dim data as Byte() = System.Text.Encoding.Default.GetBytes("*********") Dim er as EchoResult = ping1.Send("www.dart.com", 100, 1, "192.168.0.83", data) ' EchoResult er describes the ping. Display properties of the EchoResult. Debug.WriteLine("Reply from " + er.RemoteAddress) Debug.WriteLine("Bytes " + er.Data.Length) Debug.WriteLine("Time " + er.ResponseTime) Debug.WriteLine("TTL " + er.TTL)
Send comments on this topic.
Documentation version 1.1.2.0.
© 2008 Dart Communications. All rights reserved.