Stop/Start Tcp server


I've to add a Tcp Server and send data received to a mqtt remote client.
My problem is that if the broker is down i've to stop the Tcp listener (the tcp client have an internal cache if no listener is up). I've used the default Tcp server, but it has only static configuration. there is a tcp-server-dynamic but it seems to not work properly, i can start but not stop and then if i start again it tell me that there is already a listening process on port 35000 (my port).

have you some tips ?

I've seen that there is no way to disable a node by code.



Can I ask why?
Cant you simply use the MQTT nodes to send and receive data from the remote MQTT client?
The MQTT nodes will automatically re-connect after the network is "up".
Additionally, you can action the MQTT nodes to "disconnect" and "connect" at runtime.

Hi Steve

in my project i've a device that send via tcp data, i use node-red as a gateway, so i read the tcp data, serialize on json message and send i by mqtt connection. If the broker is down i've to close the tcp listener in order to use the local device's internal caching and when the broker is up i can start the tcp listener and the local device flush all data.

So i've to stop the tcp listener or i have to create in node-red a local caching.



Would it not be acceptable to simply not reply to the TCP data? or does the device sending TCP data not "care" about any acknowledgment?

the local device connect to the tcp server and if the socket is created send the data and then close. so is a simple flush based on the tcp connection creation

It might be easier just to queue them in node-red. It is very easy to build a FIFO buffer backed by persistent context in node-red.

In fact I think this flow may be what you want.

Thank's, i'll test this way, so i'll have a persistent disk storage for other data.

Hi, I've see your example and i've activate the persistent context on disk, but they are saved every 30s, i've to save every time an item is add to the list. how i can do it from code ?


It will be saved to disk every 30 seconds by default, but that can be adjusted in settings.js. It will also get saved if node red is shut down normally. The only time you would lose data is if node-red crashed or the power was cut so node-red did not shut down normally.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.