javascript - invalid non-string/buffer chunk Node.js -


i'm studying node.js @ college, , it's first time learning kind of programming language. i've got errors in attempt of chat server. when try connect 1 client server, connection closes inmmediately , appears error 'invalid non-string/buffer chunk'. upload screenshots , can check wrong, because i've been thinking while , don't find solution.

click here see git bash

my code in javascript:

 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 = 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 = 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 = nombres[sockets.indexof(socket)];        sockets.splice(i, 1);           console.log("ha salido el usuario:" + nombres[sockets.indexof(socket)]);      }     });   }    });   });   server.listen(9000); 

i think problem line socket.push(socket). mean sockets.push(socket). you're doing now, attempting push socket instance socket stream fails because, error says, it's not string or buffer.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -