代码之家  ›  专栏  ›  技术社区  ›  Alvin

将套接字响应作为十六进制字节

  •  0
  • Alvin  · 技术社区  · 6 年前

    如何作为缓冲区二进制响应?

    sock.on('data', function(data) {
            console.log('DATA ' + sock.remoteAddress + ': ' + data);
            let response = new Buffer("0000", "base64");
            setTimeout(function() {
                sockets.forEach(function(sock, index, array) {
                    sock.write(response);
                });
            }, 3000);
        });
    

    1 回复  |  直到 6 年前
        1
  •  0
  •   Holger Will    6 年前

    Buffer.from("00aabbcc","hex")
    

    Buffer.from([0x0,0xaa,0xbb,0xcc])
    

    https://nodesource.com/blog/understanding-the-buffer-deprecation-in-node-js-10/