http2session.ping([payload, ]callback)


向连接的 HTTP/2 对等方发送 PING 帧。必须提供 callback 函数。如果发送了 PING,则该方法将返回 true,否则返回 false

¥Sends a PING frame to the connected HTTP/2 peer. A callback function must be provided. The method will return true if the PING was sent, false otherwise.

未完成的(未确认的)ping 的最大数量由 maxOutstandingPings 配置选项决定。默认最大值为 10。

¥The maximum number of outstanding (unacknowledged) pings is determined by the maxOutstandingPings configuration option. The default maximum is 10.

如果提供,则 payload 必须是 BufferTypedArrayDataView,其中包含 8 个字节的数据,这些数据将与 PING 一起传输并与 ping 确认一起返回。

¥If provided, the payload must be a Buffer, TypedArray, or DataView containing 8 bytes of data that will be transmitted with the PING and returned with the ping acknowledgment.

将使用三个参数调用回调:如果 PING 被成功确认,则错误参数将为 nullduration 参数报告自发送 ping 和收到确认以来经过的毫秒数,以及包含 8 字节 PING 有效负载的 Buffer

¥The callback will be invoked with three arguments: an error argument that will be null if the PING was successfully acknowledged, a duration argument that reports the number of milliseconds elapsed since the ping was sent and the acknowledgment was received, and a Buffer containing the 8-byte PING payload.

session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
  if (!err) {
    console.log(`Ping acknowledged in ${duration} milliseconds`);
    console.log(`With payload '${payload.toString()}'`);
  }
}); 

如果未指定 payload 参数,则默认负载将是标记 PING 持续时间开始的 64 位时间戳(小端)。

¥If the payload argument is not specified, the default payload will be the 64-bit timestamp (little endian) marking the start of the PING duration.