서버 :Node.js가 Client에 Server 입력을 보냅니다. 메모리 누수에 대한 경고. 내 실수는 무엇입니까? 그리고 node.js는 어떻게 코드를 실행합니까?
var net = require('net');
var stdin = process.openStdin();
var client_list = [];
var server = net.createServer(function(connection) {
//console.log('client connected');
connection.on('error', function(e){
if(e.code == 'ECONNRESET'){
console.log('Client dissconeccted');
}
});
//connection.write('Hello World!\r\n');
stdin.addListener("data", function(d) {
// note: d is an object, and when converted to a string it will
// end with a linefeed. so we (rather crudely) account for that
// with toString() and then trim()
console.log("you entered: [" + d.toString().trim() + "]");
connection.write(d.toString().trim());
});
connection.pipe(connection);
});
server.listen(9999, function() {
console.log('server is listening');
});
클라이언트 (?) :
"Possible EventEmitter memory leak detected. 11 data listeners added. Use emitter.setMaxListeners() to increase limit".
왜
var net = require('net');
var HOST = 'localhost';
var PORT = 9999;
//var client = new net.Socket();
var client = net.connect(PORT, HOST, function(){
console.log('connected to server! ' + HOST + ':' + PORT);
//client.write('I am Superman');
});
client.on('data', function(data) {
var data = data.toString();
console.log(data);
//If data starts with JS add injection functionallity
if (data === "END"){
client.end();
console.log("ENDING!")
}
else if (data === "poo"){
console.log("HOLY SHIT!")
}
});
//Keep trying to connect!
client.on('error', function(e) {
console.log('Parent connection error');
//client.end();
client.connect(PORT, HOST);
});
client.on('end', function() {
console.log('disconnected from server');
});
/*var client = net.connect({port: 8080}, function() {
console.log('connected to server!');
});*/
그래서 무슨 일이 추가 청취자를 유지하고 메시지와 함께 11 청취자 날을 경고이다 이거 야? stdin.addListener()
을 움직여 문제를 해결하려고했지만 입력을 전혀받지 않거나 문제가 지속됩니다. 내가 뭔가? 노드에서 코드가 실행되는 방식은 무엇입니까?
미리 감사드립니다.
{ "이름": "TCP", "버전": "1.0.0", "설명": "TCP 클라이언트/서버 테스트", "주": "server.js" "스크립트": { "test": "echo \"오류 : 테스트를 지정하지 않았습니다. \ "&& exit 1" , "author": "Juliet", "라이센스": "ISC", "dependencies" { "net": "^ 1.0.2" } } –