Thursday, 15 May 2014

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


I have a node in college I'm reading JS, and this is my first time in learning programming languages ​​like this. Some errors were found in my chat server attempt. When I try to connect a client to the server, the connection stops and the error 'invalid non-string / buffer chunk' appears. I upload some screenshots And you can see what is wrong, because I was thinking about it for a while and I did not find any solution.

My code is in javascript:

  var net = requires ('net'); Var s = required sockets = []; Var nombres = []; Var nombresUsados ​​= []; Console.log ("This High Six Innseo El Savior"); Var server = net.createServer {socket.push (socket); nombres.push ("Client:" + sockets. Indochoff (socket)); NombersUsados ​​Pius ("client:" + socket. Indochoff (socket) ;); Console.log ("Client espadodo, nick:" + nombres [sockets.indexOf (socket)]); socket. Written ("bienveno" + numbers [sockets. Indexoff (socket) + "\ n"); ! [Enter image details here] [2] socket.On ('data', function (D) {var entrada = d.toString (); uruureuINICO = entara match (/ ^ msg /); var cambirer (= ^ "Exit"); if (cambiarNick == "nick") {var repetido = 0; var nombresSinNick = entrada.replace (cambiarNick, ''); (Var i = nombres.length-1; i & lt; = 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 ( ); Proc Ess.on ('uncaughtException', function (mistake) {socket.write ("to \ n"); }); Socket.write ("OK." + Nombres [sockets.indexOf (socket)] + "\ n"); Console.log (nombresUsados ​​[sockets.indexOf (socket)]) + "Su Nambre Hasido Cambodo por:" + numbers [sockets. Indicate (socket)]; NombresUsados ​​[sockets.indexOf (socket)] = nombresSinNick.trim (); }} And if (UsuarioUnico = "msg") {var nombresSinMsg = entrada.replace (UsuarioUnico, ''); Var encontrado = 0; (Var i = nombres.length-1; i & lt; = 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 == 'quit') {var i = nombres [sockets.indexOf (socket)]; sockets.splice (i, 1 ); Console.log ("Hey Aldi:" + nombres [sockets.indexOf (socket)]);}}); }}); }); Server.listen (9000);  

I think the problem line is socket.push (socket) < / Code>. Maybe you mean sockets.push (socket) . Now what you are doing, trying to push the socket frequency into the socket current which fails, because the error says it is not a string or a buffer.


No comments:

Post a Comment