PingReply.Buffer 属性

定义

获取 Internet 控制消息协议 (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[]

包含 ICMP 回送答复消息中收到的数据的 Byte 数组,如果没有收到答复,则为空数组。

示例

下面的代码示例同步发送 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节中的“跟踪路由”。

与 一起使用 Send 的默认缓冲区包含 SendAsync 32 个字节的数据。

适用于