1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Clean up tcpget node connected status.

to address #759
This commit is contained in:
Dave Conway-Jones 2015-11-30 22:05:26 +00:00
parent 3d5ed840dc
commit a47ad4842a

View File

@ -397,8 +397,7 @@ module.exports = function(RED) {
} }
if (!node.connected) { if (!node.connected) {
client = net.Socket(); client = net.Socket();
if (socketTimeout) { client.setTimeout(socketTimeout); } if (socketTimeout !== null) { client.setTimeout(socketTimeout); }
//node.status({});
var host = node.server || msg.host; var host = node.server || msg.host;
var port = node.port || msg.port; var port = node.port || msg.port;
var m; var m;
@ -471,24 +470,31 @@ module.exports = function(RED) {
}); });
client.on('end', function() { client.on('end', function() {
//console.log("END");
node.connected = false; node.connected = false;
node.status({}); node.status({fill:"grey",shape:"ring",text:"common.status.disconnected"});
node.send({"payload":m}); node.send({"payload":m});
client = null; client = null;
}); });
client.on('close', function() { client.on('close', function() {
node.status({}); //console.log("CLOSE");
node.connected = false;
if (node.done) { node.done(); } if (node.done) { node.done(); }
}); });
client.on('error', function() { client.on('error', function() {
node.error(RED._("tcpin.errors.connect-fail"),msg); //console.log("ERROR");
node.connected = false;
node.status({fill:"red",shape:"ring",text:"common.status.error"}); node.status({fill:"red",shape:"ring",text:"common.status.error"});
node.error(RED._("tcpin.errors.connect-fail"),msg);
if (client) { client.end(); } if (client) { client.end(); }
}); });
client.on('timeout',function() { client.on('timeout',function() {
//console.log("TIMEOUT");
node.connected = false;
node.status({fill:"grey",shape:"dot"});
node.warn(RED._("tcpin.errors.connect-timeout")); node.warn(RED._("tcpin.errors.connect-timeout"));
if (client) { if (client) {
client.end(); client.end();
@ -511,6 +517,7 @@ module.exports = function(RED) {
buf = null; buf = null;
client.destroy(); client.destroy();
} }
node.status({});
if (!node.connected) { done(); } if (!node.connected) { done(); }
}); });