我想使用nodejs做tcp通信 我使用了下面的代码做测试: var net = require(‘net’);
var HOST = ‘127.0.0.1’;
var PORT = 6969;
var tcpserver= net.createServer(function(sock) {
console.log('CONNECTED: ’ + sock.remoteAddress + ‘:’ + sock.remotePort);
sock.on(‘data’, function(data) {
console.log('DATA ’ + sock.remoteAddress + ': ’ + data);
sock.write(‘You said "’ + data + ‘"’);
});
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress + ' ' + sock.remotePort);
});
}) tcpserver.listen(PORT, HOST);
console.log(‘Server listening on ’ + HOST +’:’+ PORT);
当连接到11个客户端的时候提示 warning: possible EventEmitter memory leak detected. 11 uncaughtException listeners added. Use emitter.setMaxListeners() to increase limit.
我尝试添加sock.setMaxListeners(0); 还是无效 请教下用过net做TCP通信的朋友告诉下应该怎么做 nodejs的版本是4.4.5