http2session.ping([payload, ]callback)
历史
| 版本 | 变化 | 
|---|---|
| v18.0.0 | 将无效回调传递给   | 
| v8.9.3 | 添加于:v8.9.3  | 
参数
payload<Buffer> | <TypedArray> | <DataView> 可选 ping 负载。callback<Function>- 返回: <boolean>
 
向连接的 HTTP/2 对等方发送 PING 帧。必须提供callback 函数。如果发送了PING,则该方法将返回true,否则返回false。
未完成(未确认)ping 的最大数量由maxOutstandingPings 配置选项确定。默认最大值为 10。
如果提供,payload 必须是 Buffer 、 TypedArray 或 DataView 包含 8 个字节的数据,这些数据将与 PING 一起传输并与 ping 确认一起返回。
回调将使用三个参数调用:如果成功确认 PING,则错误参数将是 null,报告自发送 ping 并收到确认以来经过的毫秒数的 duration 参数,和一个包含 8 字节 PING 有效载荷的 Buffer。
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 位时间戳(小端序)。
相关用法
- Node.js Http2Session.setLocalWindowSize(windowSize)用法及代码示例
 - Node.js Http2Session stream用法及代码示例
 - Node.js Http2Session timeout用法及代码示例
 - Node.js Http2Session Close用法及代码示例
 - Node.js Http2ServerResponse.finished用法及代码示例
 - Node.js Http2ServerResponse.getHeaderNames()用法及代码示例
 - Node.js Http2ServerResponse.statusMessage用法及代码示例
 - Node.js Http2ServerResponse.writableEnded用法及代码示例
 - Node.js Http2ServerRequest.stream用法及代码示例
 - Node.js Http2ServerResponse.setHeader()用法及代码示例
 - Node.js Http2ServerRequest.method用法及代码示例
 - Node.js Http2ServerResponse.getHeader()用法及代码示例
 - Node.js Http2ServerResponse.addTrailers()用法及代码示例
 - Node.js Http2ServerRequest.url用法及代码示例
 - Node.js Http2ServerResponse.setTimeout()用法及代码示例
 - Node.js Http2ServerRequest.complete用法及代码示例
 - Node.js Http2ServerResponse.stream用法及代码示例
 - Node.js Http2ServerRequest.destroy()用法及代码示例
 - Node.js Http2ServerResponse.removeHeader()用法及代码示例
 - Node.js Http2ServerResponse.hasHeader()用法及代码示例
 - Node.js Http2ServerRequest.aborted用法及代码示例
 - Node.js Http2ServerResponse.getHeaders()用法及代码示例
 - Node.js Http2ServerRequest.rawTrailers用法及代码示例
 - Node.js Http2ServerRequest.rawHeaders用法及代码示例
 - Node.js Http2ServerResponse close用法及代码示例
 
注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品 Http2Session.ping([payload, ]callback)。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
