PingReply.RoundtripTime プロパティ

定義

インターネット制御メッセージ プロトコル (ICMP) エコー要求を送信し、対応する ICMP エコー応答メッセージを受信するのにかかった時間 (ミリ秒) を取得します。

public:
 property long RoundtripTime { long get(); };
public long RoundtripTime { get; }
member this.RoundtripTime : int64
Public ReadOnly Property RoundtripTime As Long

プロパティ値

ラウンド トリップ時間をミリ秒単位で指定する Int64

次のコード例では、ICMP エコー要求を同期的に送信し、このプロパティによって返されるバッファーのサイズを表示します。

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);
    }
}

注釈

Echo 要求が失敗した場合、 RoundtripTime 時間は 0 として報告されます。これは、要求が成功した場合にも有効な値です。 このプロパティによって返される値を無視するかどうかを判断するには、 Status を確認する必要があります。

適用対象