如何简单地从节点js中的套接字读取二进制数字?

时间:2015-08-10 07:08:45

标签: node.js sockets binary buffer

在下面的代码中,有什么方法可以简单地记录二进制数据而不转换为字符串?

var server  = net.createServer(function(sock) {

console.log('CONNECTED: ' + sock.remoteAddress +':'+ sock.remotePort);


sock.on('data', function(data) {

    console.log('DATA ' + sock.remoteAddress + ': ' + data);

    sock.write('You said "' + data + '"');

});

sock.on('close', function(data) {
    console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});

})

1 个答案:

答案 0 :(得分:0)

尝试这样的代码

server.on('connection', function (socket) {
    socket.on('data', function (bufferData) {
        console.log(bufferData);
    })
})