io.sockets.on( "connection", function( socket ){
console.log('socket connect');
let client = modbus.client.tcp.complete({
'host' : '192.168.1.8',
'port' : 10000,
'autoReconnect' : false,
'reconnectTimeout' : 1000,
'timeout' : 5000,
'unitId' : 1
});
client.connect();
client.on('connect', function () {
console.log('modbus');
setInterval(function(){
client.readInputRegisters(1,24).then(function(resp){
let arr=resp.payload;
socket.emit('info',arr);
},console.error);
},1000);
socket.on('switch',function(msg){
console.log(msg.flag+" "+msg.on);
client.writeSingleCoil(msg.flag, msg.on).then(function (resp) {
console.log(resp);
}, console.error);
console.log(msg);
});
socket.on('disconnect',function(socket){
console.log('socket disconnect');
client.close();
delete client;
});
});
client.on('error', function (err) {
console.log(err);
});
client.on('close', function () {
console.log('modbus close');
});
});
↧
可以帮我看一下这段websockets代码是哪里导致的内存溢出?
↧