mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Turn on tcp node socket keepalive when in server mode
This commit is contained in:
parent
1dbec5eca8
commit
1ee5e50d50
@ -125,10 +125,12 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var server = net.createServer(function (socket) {
|
var server = net.createServer(function (socket) {
|
||||||
|
socket.setKeepAlive(true,120000);
|
||||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||||
var id = (1+Math.random()*4294967295).toString(16);
|
var id = (1+Math.random()*4294967295).toString(16);
|
||||||
connectionPool[id] = socket;
|
connectionPool[id] = socket;
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:++count})});
|
count++;
|
||||||
|
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
||||||
|
|
||||||
var buffer = (node.datatype == 'buffer')? new Buffer(0):"";
|
var buffer = (node.datatype == 'buffer')? new Buffer(0):"";
|
||||||
socket.on('data', function (data) {
|
socket.on('data', function (data) {
|
||||||
@ -175,7 +177,8 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
socket.on('close', function() {
|
socket.on('close', function() {
|
||||||
delete connectionPool[id];
|
delete connectionPool[id];
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:--count})});
|
count--;
|
||||||
|
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
||||||
});
|
});
|
||||||
socket.on('error',function(err) {
|
socket.on('error',function(err) {
|
||||||
node.log(err);
|
node.log(err);
|
||||||
@ -303,6 +306,7 @@ module.exports = function(RED) {
|
|||||||
var connectedSockets = [];
|
var connectedSockets = [];
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:0})});
|
node.status({text:RED._("tcpin.status.connections",{count:0})});
|
||||||
var server = net.createServer(function (socket) {
|
var server = net.createServer(function (socket) {
|
||||||
|
socket.setKeepAlive(true,120000);
|
||||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||||
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
||||||
node.log(RED._("tcpin.status.connection-from",{host:socket.remoteAddress, port:socket.remotePort}));
|
node.log(RED._("tcpin.status.connection-from",{host:socket.remoteAddress, port:socket.remotePort}));
|
||||||
|
Loading…
Reference in New Issue
Block a user