improved error handling (and labelling) for socket node... but not perfect by a long way...

This commit is contained in:
Dave C-J 2013-09-06 21:43:54 +01:00
parent 3255ae4187
commit 38d309dcf3
4 changed files with 10 additions and 6 deletions

View File

@ -59,7 +59,7 @@
outputs:1, outputs:1,
icon: "bridge-dash.png", icon: "bridge-dash.png",
label: function() { label: function() {
return this.name||this.topic||(this.transport+":"+this.port); return this.name||this.topic||("socket "+this.transport+":"+this.port);
}, },
labelStyle: function() { labelStyle: function() {
return this.name?"node_label_italic":""; return this.name?"node_label_italic":"";

View File

@ -55,8 +55,13 @@ function SocketIn(n) {
node.send(msg); node.send(msg);
}); });
}); });
server.on('error', function (e) {
if (e.code == 'EADDRINUSE') {
setTimeout(node.error('TCP port is already in use - please reconfigure socket.'),250);
}
});
server.listen(node.port); server.listen(node.port);
node.log('tcp listener on port :'+node.port+'/'); node.log('tcp listener on port :'+node.port);
this._close = function() { this._close = function() {
server.close(); server.close();
@ -130,5 +135,3 @@ RED.nodes.registerType("socket in",SocketIn);
SocketIn.prototype.close = function() { SocketIn.prototype.close = function() {
this._close(); this._close();
} }

View File

@ -57,7 +57,7 @@
icon: "bridge-dash.png", icon: "bridge-dash.png",
align: "right", align: "right",
label: function() { label: function() {
return this.name||this.topic||(this.transport+":"+this.port); return this.name||this.topic||("socket "+this.transport+":"+this.port);
}, },
labelStyle: function() { labelStyle: function() {
return (this.name||!this.topic)?"node_label_italic":""; return (this.name||!this.topic)?"node_label_italic":"";

View File

@ -40,7 +40,8 @@ function SocketOut(n) {
node.error('tcp : '+err); node.error('tcp : '+err);
}); });
client.connect(this.port, this.host, function() { client.connect(this.port, this.host, function() {
client.end(msg.payload); try { client.end(msg.payload); }
catch (e) { node.error(e); }
}); });
} }
if (this.trans == "udp") { if (this.trans == "udp") {