samedi 4 avril 2015

Is node.js net server data event object a buffer?

I'm attempting to make a tcp game server in node.js but am having problems with data transmission. I want to get the length (in bytes) of the buffer i receive in the sockets DATA event so logically, under the assumption that the object is a buffer (from what i've read) i tried this :



var server = net.createServer();
server.on("connection", function(socket) {

socket.on("data", function(data) {
console.log(data.length);
});

});


But apparently it returns undefined. This confused me quite alot so i tried to see if i'm even handling a buffer here by doing this :



var server = net.createServer();
server.on("connection", function(socket) {

socket.on("data", function(data) {
console.log(Buffer.isBuffer(data));
});

});


And i got false! Could anybody explain what i'm doing wrong? ps. i have no encoding set on the socket


Aucun commentaire:

Enregistrer un commentaire