Maybe I should create a separate topic? Because this one is for dynamic node disable
Perhaps msg.reset is what you want
In itself, you need to trigger the closing of your TCP node. So you can create a test code in one of your node that reacts to RED.httpAdmin (for example) and calls yourTcpNode.close(). I have never tried and the node will not be usable after that without a reboot.
As Matthias and me said there are only two possibilities at the moment:
- deployment to disable the node
- custom TCP node with button to trigger a close event
Won't bother, I doubt very much that a) that is the solution to your problem b) that anyone else would need this feature (see a)).
What about msg.reset
msg.reset doesn't work because it drops connection but with another request it will be restored, where in reality after tcp listener is not available anymore it will generate a connection timeout error
so I could automate the test with msg.reset, then change msg.host and msg.port to get the same status messages
This actually works:
[{"id":"9ca116c3ccd7fca7","type":"http in","z":"cb92e457310576e3","name":"","url":"/suddendeath","method":"get","upload":false,"swaggerDoc":"","x":353,"y":482,"wires":[["846036026b9e42bf"]]},{"id":"846036026b9e42bf","type":"function","z":"cb92e457310576e3","name":"function 35","func":"msg.res._res.socket.destroy()\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":592,"y":580,"wires":[[]]}]
produces this result when accessed with curl:
prompt> curl -v http://localhost:1880/suddendeath
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to renderbox (127.0.0.1) port 1880 (#0)
> GET /suddendeath HTTP/1.1
> Host: localhost:1880
> User-Agent: curl/7.63.0
> Accept: */*
>
* Empty reply from server
you want to disable the tcp in node to simulate a missing tcp server? ok that's another kettle of fish.
That's correct
That's not possible.
Unfortunately the tcp in has no input port therefore it can't be sent an msg to stop. So it would seem a custom tcp in node that takes "control messages" to start and stop it would be what you're looking for.
Far simpler to implement than a "dynamic disable node" feature!
Another way you could do it is with flow context
and switch
nodes.
You set a flow context
from one value to another and that would change how the message goes through the switch
node.
Basic flow:
[{"id":"ada8918a8229e0a4","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"A","payloadType":"str","x":210,"y":4130,"wires":[["8cd0894a22cf4a28"]]},{"id":"3cc28e0b370e79ee","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"B","payloadType":"str","x":210,"y":4170,"wires":[["8cd0894a22cf4a28"]]},{"id":"8cd0894a22cf4a28","type":"change","z":"0918ee609bf69fc7","name":"","rules":[{"t":"set","p":"condition1","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":4150,"wires":[[]]},{"id":"faadf22acfa69730","type":"inject","z":"0918ee609bf69fc7","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"This is a message","payloadType":"str","x":200,"y":4260,"wires":[["0f640bd0ea104d41"]]},{"id":"0f640bd0ea104d41","type":"switch","z":"0918ee609bf69fc7","name":"","property":"condition1","propertyType":"flow","rules":[{"t":"eq","v":"A","vt":"str"},{"t":"eq","v":"B","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":380,"y":4260,"wires":[["69dc21f4e3746808"],["b8eba76d471ec67e"]]},{"id":"69dc21f4e3746808","type":"debug","z":"0918ee609bf69fc7","name":"A","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":4210,"wires":[]},{"id":"b8eba76d471ec67e","type":"debug","z":"0918ee609bf69fc7","name":"B","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":4290,"wires":[]}]
Then you see how the message goes to different places.
I was just playing around with a custom node that actually closes all tcp in nodes. It's a hack and not something to be proud of but it does shutdown the tcp in node:
node.on("input", function (msg, send, done) {
try {
RED.nodes.eachNode(nde => {
if (nde.type == "tcp in") {
RED.nodes.getNode(nde.id).close()
}
})
send(msg);
done();
} catch (err) {
console.error(err)
node.error("error occurred", { ...msg, error: err })
done();
}
})
Obviously this isn't nice thing to be doing since a third-party node is affecting a non-related node. This can't be done in a function node because access to RED.nodes.eachNode
is not possible via function node.