PingReply.RoundtripTime Properti
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mendapatkan jumlah milidetik yang diambil untuk mengirim permintaan gema Internet Control Message Protocol (ICMP) dan menerima pesan balasan gema ICMP yang sesuai.
public:
property long RoundtripTime { long get(); };
public long RoundtripTime { get; }
member this.RoundtripTime : int64
Public ReadOnly Property RoundtripTime As Long
Nilai Properti
Yang Int64 menentukan waktu pulang pergi, dalam milidetik.
Contoh
Contoh kode berikut mengirimkan permintaan gema ICMP secara sinkron dan menampilkan ukuran buffer yang dikembalikan oleh properti ini.
void ComplexPing()
{
Ping ^ pingSender = gcnew Ping;
// Create a buffer of 32 bytes of data to be transmitted.
String^ data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
array<Byte>^buffer = Encoding::ASCII->GetBytes( data );
// Wait 10 seconds for a reply.
int timeout = 10000;
// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions ^ options = gcnew PingOptions( 64,true );
// Send the request.
PingReply ^ reply = pingSender->Send( "www.contoso.com", timeout, buffer, options );
if ( reply->Status == IPStatus::Success )
{
Console::WriteLine( "Address: {0}", reply->Address->ToString() );
Console::WriteLine( "RoundTrip time: {0}", reply->RoundtripTime );
Console::WriteLine( "Time to live: {0}", reply->Options->Ttl );
Console::WriteLine( "Don't fragment: {0}", reply->Options->DontFragment );
Console::WriteLine( "Buffer size: {0}", reply->Buffer->Length );
}
else
{
Console::WriteLine( reply->Status );
}
}
public static void ComplexPing ()
{
Ping pingSender = new Ping ();
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes (data);
// Wait 10 seconds for a reply.
int timeout = 10000;
// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions options = new PingOptions (64, true);
// Send the request.
PingReply reply = pingSender.Send ("www.contoso.com", timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine ("Address: {0}", reply.Address.ToString ());
Console.WriteLine ("RoundTrip time: {0}", reply.RoundtripTime);
Console.WriteLine ("Time to live: {0}", reply.Options.Ttl);
Console.WriteLine ("Don't fragment: {0}", reply.Options.DontFragment);
Console.WriteLine ("Buffer size: {0}", reply.Buffer.Length);
}
else
{
Console.WriteLine (reply.Status);
}
}
Keterangan
Jika permintaan Echo gagal, waktu dilaporkan RoundtripTime sebagai 0, yang juga merupakan nilai yang valid ketika permintaan berhasil. Anda harus memeriksa Status untuk menentukan apakah nilai yang dikembalikan oleh properti ini harus diabaikan.