Answer the question
In order to leave comments, you need to log in
Why is node.js crashing?
I found a script for creating a chat on note.js on the net. Launched the script. Connected to server via XMLSocket in AS3. Everything worked, messages were sent, displayed in other windows running on 1 computer. But when launched on another computer connected via local network, the server crashes.
Here is the actual server code:
//Загрузка TCP библиотеки
EventEmitter= require('events').EventEmitter;
var server=new EventEmitter;
net=require('net');
//var mysql = require('mysql');
var clients=[];
//старт TCP сервера
net.createServer(function(socket) {
socket.setEncoding("utf8");
socket.name=socket.remoteAddress+":"+socket.remotePort
console.log(socket.name);
clients.push(socket);
socket.write(JSON.stringify ({Welcome:socket.name}).toString() + "\0");
socket.on('data',function(data) {
broadcast(data,socket)
});
function handleAction(datas,sock)
{
var obj = JSON.parse(datas,substr(0,datas.length-1));
}
socket.on('end',function () {
clients.splice(clients.indexOf(socket),1);
broadcast(socket.name+" left the chat.\n",socket);
});
server.on('error',function(){
});
server.emit('error');
function broadcast(message,sender){
clients.forEach(function(client){
//if (client===sender) return;
client.write(JSON.stringify ({message}).toString() + "\0");
console.log(sender);
});
}
}).listen(8080,"192.168.1.2");
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question