mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add err handler on tcpout/listener. Fixes #50
This commit is contained in:
parent
6fb8506722
commit
488a039781
@ -71,15 +71,13 @@ function TcpOut(n) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
node.on("close", function() {
|
||||||
this._close = function() {
|
|
||||||
this.closing = true;
|
this.closing = true;
|
||||||
client.end();
|
client.end();
|
||||||
clearTimeout(reconnectTimeout);
|
clearTimeout(reconnectTimeout);
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
} else {
|
||||||
var connectedSockets = [];
|
var connectedSockets = [];
|
||||||
var server = net.createServer(function (socket) {
|
var server = net.createServer(function (socket) {
|
||||||
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
||||||
@ -89,6 +87,11 @@ function TcpOut(n) {
|
|||||||
node.log("connection closed from "+remoteDetails);
|
node.log("connection closed from "+remoteDetails);
|
||||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||||
});
|
});
|
||||||
|
socket.on('error',function() {
|
||||||
|
node.log("socket error from "+remoteDetails);
|
||||||
|
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
node.on("input", function(msg) {
|
node.on("input", function(msg) {
|
||||||
if (msg.payload != null) {
|
if (msg.payload != null) {
|
||||||
@ -109,16 +112,12 @@ function TcpOut(n) {
|
|||||||
server.listen(node.port);
|
server.listen(node.port);
|
||||||
node.log('listening on port '+node.port);
|
node.log('listening on port '+node.port);
|
||||||
|
|
||||||
this._close = function() {
|
node.on('close', function() {
|
||||||
server.close();
|
server.close();
|
||||||
node.log('stopped listening on port '+node.port);
|
node.log('stopped listening on port '+node.port);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("tcp out",TcpOut);
|
RED.nodes.registerType("tcp out",TcpOut);
|
||||||
|
|
||||||
TcpOut.prototype.close = function() {
|
|
||||||
this._close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user