How To Get Connections Number For TCP In Node?

Hi All,

Is there a way to know the number of connections of TCP In Node? Because i want to make status if the TCP is connected or not connected.



Use the status node

1 Like

Hi Steve,
Thank you. It's works!

Hi @Steve-Mcl

How to check the status with interval ? For example, check the connection every 5 seconds

Correct me if I’m wrong, but with Node-RED being event driven I believe the status node only publishes a message if the status changes. What you can do is store the output of the status node in a flow variable, then add an inject node to be repeated at your interval, and have it get the data from the flow variable. That way the changes are stored, and you can poll it every 5 seconds even if the status doesn’t change. Depending on how you wire it you can also forward it again as soon as the status changes, and not just on your polling interval.
Edit: do not do the above, like Dave says below :slight_smile: There's definitely better ways like described further down this thread

Uuugh. No that IS an antipattern :wink:

Why do you want to check it every 5 seconds? The status node will send a new message each time the status changes so a downstream node will get told when the number changes. There you can check for zero/non-zero and take appropriate action. Why do you need to do more than that?
If what you actually want to do is check for it being zero for a certain time then you can use a Trigger node. Use a Switch node to route zero/non-zero counts to different outputs, then feed the zero message into a Trigger set to send nothing, then after a time send the watchdog message. Pass the non-zero output from the Switch through a Change node which sets msg.reset and pass that on to the Trigger node also.

Hi All,
Thank you for all advises. Likes Colin said,It's better to wait the status node output. The output will be change as a current input status

1 Like