【问题标题】:How to send an HTTP/2 frame to server in Node.js如何在 Node.js 中向服务器发送 HTTP/2 帧
【发布时间】:2017-01-29 07:53:38
【问题描述】:

使用以下代码:

var req = http2.request({
    hostname: 'api.push.apple.com',
    protocol: 'https:',
    port: 443,
    method: 'POST',
    path: '/3/device/' + deviceToken,
    agent: new http2.Agent({log: logger}),
    headers: {
        'apns-topic': 'web.com.example'
    },
    cert: cert,
    key: key,
}, function(res) {
    res.pipe(process.stdout);
});
req.write(JSON.stringify(post));
req.end();

如何发送PING 帧来检查我与node-http2 模块的连接状况?

提前致谢。

【问题讨论】:

  • Ping 是完全不同的协议,与 HTTP/2 无关
  • @FabianBettag - ping frame 是一个不同于 ping 程序的 http2 事物。见http2.github.io/http2-spec/#PING
  • 那我很抱歉。
  • 你使用哪个节点版本? v8.x.x 中有一个函数ping

标签: node.js http connection ping http2


【解决方案1】:

来自Node.js HTTP/2 Documentation

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 2021-10-10
    相关资源
    最近更新 更多