共用方式為


PingReply.Buffer 屬性

定義

取得在網際網路控制訊息通訊協定 (ICMP) 回應回覆訊息中所收到的資料緩衝區。

public:
 property cli::array <System::Byte> ^ Buffer { cli::array <System::Byte> ^ get(); };
public byte[] Buffer { get; }
member this.Buffer : byte[]
Public ReadOnly Property Buffer As Byte()

屬性值

Byte[]

Byte 陣列,包含在 ICMP 回應回覆訊息中所收到的資料,如果沒有收到回覆則為空陣列。

範例

下列程式代碼範例會同步傳送ICMP回應要求,並顯示這個屬性傳回的緩衝區大小。

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

備註

以ICMP回應要求傳送的數據緩衝區會傳回給回應回復中的傳送者,以便計算已知大小的封包往返行程時間。 結合 選項的數據緩衝區 DontFragment 可用來探索來源與目的地計算機之間網路路徑的最大傳輸單位。 如需詳細資訊,請參閱 RFC 1574 第 3.2 節中的「追蹤路由」,網址為 https://www.ietf.org

與 搭配SendSendAsync使用的默認緩衝區,包含32個字節的數據。

適用於