Add err handler on tcpout/listener. Fixes #50

This commit is contained in:
Nicholas O'Leary 2013-10-27 17:57:46 +00:00
parent 6fb8506722
commit 488a039781
1 changed files with 93 additions and 94 deletions

View File

@ -71,15 +71,13 @@ function TcpOut(n) {
}
});
this._close = function() {
node.on("close", function() {
this.closing = true;
client.end();
clearTimeout(reconnectTimeout);
}
}
});
else {
} else {
var connectedSockets = [];
var server = net.createServer(function (socket) {
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
@ -89,6 +87,11 @@ function TcpOut(n) {
node.log("connection closed from "+remoteDetails);
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) {
if (msg.payload != null) {
@ -109,16 +112,12 @@ function TcpOut(n) {
server.listen(node.port);
node.log('listening on port '+node.port);
this._close = function() {
node.on('close', function() {
server.close();
node.log('stopped listening on port '+node.port);
}
});
}
}
RED.nodes.registerType("tcp out",TcpOut);
TcpOut.prototype.close = function() {
this._close();
}