Invalid non-line / buffer block Node.js

I study Node.js in college, and I first studied this kind of programming language. I have some errors in trying a chat server. When I try to connect one client to the server, the connection closes immediately and the error "Invalid non-lane / buffer piece" appears. I am uploading a few screenshots and you can check what is wrong because I have been thinking about this for a while and I have not found any solution.

Click here to see my git bash

My Javascript Code:

var net = require('net'); var s = require var sockets = []; var nombres = []; var nombresUsados = []; console.log("Se ha iniciado el sevidor"); var server = net.createServer(function(socket){ socket.push(socket); nombres.push("Cliente:" + sockets.indexOf(socket)); nombresUsados.push("Cliente:" + socket.indexOf(socket)); console.log("Cliente aceptado, nick:" + nombres[sockets.indexOf(socket)]); socket.write("Bienvenido" + nombres[sockets.indexOf(socket)]+ "\n"); ![enter image description here][2]socket.on('data', function(d){ var entrada = d.toString(); var UsuarioUnico = entrada.match(/^msg/); var cambiarNick = entrada.match(/^nick/); var quit = entrada.match(/^quit/); if(cambiarNick == "nick"){ var repetido = 0; var nombresSinNick = entrada.replace(cambiarNick, ''); for(var i = nombres.length-1; i<=0; i--){ if( nombresSinNick.substring(0,nombres[i].toString().length) == nombres[i].toString()){ socket.write("KO, escoja otro nombre\n") repetido = 1; } }; if(repetido == 0){ nombres[sockets.indexOf(socket)] == nombresSinNick.trim(); process.on('uncaughtException', function(err){ socket.write("KO\n"); }); socket.write("OK. " + nombres[sockets.indexOf(socket)] + "\n"); console.log(nombresUsados[sockets.indexOf(socket)]) + "su nombre ha sido cambiado por:" + nombres[sockets.indexOf(socket)]; nombresUsados[sockets.indexOf(socket)] = nombresSinNick.trim(); } } else if (UsuarioUnico = "msg"){ var nombresSinMsg = entrada.replace(UsuarioUnico, ''); var encontrado = 0; for(var i = nombres.length-1; i<=0; i--){ if( nombresSinMsg.substring(0,nombres[i].toString().length) == nombres[i].toString()){ var mensaje = nombresSinMsg.replace(nombres[i], ''); } }; socket.on('end', function() { // CALLBACK: desconexión de cliente if(quit == 'quit'){ var i = nombres[sockets.indexOf(socket)]; sockets.splice(i, 1); console.log("Ha salido el usuario:" + nombres[sockets.indexOf(socket)]); } }); } }); }); server.listen(9000); 
+7
javascript github vagrant chat
source share
1 answer

I think the problem is in the line socket.push(socket) . You probably mean sockets.push(socket) . What you are doing now is trying to insert a socket instance into the socket stream, which fails because, as the error says, this is not a string or buffer.

+5
source share

All Articles