TCP flow, almost got it working

#1

I am using the TCP nodes to solve something that would be super easy in MQTT. Why? Because the "server" side hardware does not support MQTT and there is nothing I can do about that fact.

Case: An IOT device is hosing a server on a fixed IP and PORT, there is only one connection active in the device so I do not need to figure out the end client. Communication can be initiated either by the IOT or Nodered. Nodered is connected to several similar IOT devices but using different IP to each but same PORT on the IOT.

Problem: If I use TCPin and TCPout nodes I can connect to IOT, receive a message from an IOT. When replying I face the _session problem so messages get sent to more or less everywhere.

So I use the TCPrequest node. This works really well, all communication is separated but it does not auto connect to the remote server. This node does Connect and Send in sequence. Because the IOT device is a bit slow I loose the first package and if "Never close" option is selected the next package gets delivered because the socket is already open.

So my questions are how do I get around this? Is there any way to make the TCPrequest node auto connect in a similar way as the TCPin node? Or how do I lock an connected TCPin node to a corresponding TCPout node before I have received any data in the TCPin node? Because as I understand there is no message sent when the TCPin node makes connect?

Help?? :slight_smile:
Other than this, no problem.....

#2

so if you use the in and out nodes to connect TO a device - then surely they have unique ip addresses ? so you can address them individually ? If you are listening for connections then as soon as they send something they will send a session so you can reply individually ?

but yes there is the small gap where you may need to provoke the device to get a response and if it has connected (as one of many) then you don't yet know it's session in order to kick it privately (as it were).

In v0.20 we have added the ability for the status to handle extra parameters - so if you use a status node to catch the status events and point it at the tcp in node - then you should get a msg.status that contains amongst other properties a _session object you can then use.

#4

Excellent! I will test this as soon as possible. But it is my impression (not verified fact) that a message is copied to all TCPout nodes regardless of IP number if the _session part is left out. That´s why was so surprised that messages to xxx.xxx.xxx.121 also were sent to xxx.xxx.xxx.122. I can totally understand why it would be copied and sent to all connected clients on the same IP but not why it would cross an IP address border. Please don't take this as fact because I have not to 100% verified this, when things does not work I blame myself as a beginner in Nodered.

Have a great weekend