How to distinguish TCP connections with TCP IN/OUT nodes?

Hello Node-Red community!

I have a problem with distinguishing TCP connections.

I have multiple devices connected to me using TCP IN node via port XXX. If i send any information using TCP OUT node, all the devices receive that info, while i need to send it only to a specific device.

Even if i move each device to a diffrent port, diffrent TCP IN and TCP OUT nodes, sending commands via one of TCP OUT nodes still causes all of the devices to receive that command.

Please note that devices are redirected to me from the router's external ip, so all the devices have ip of 192.168.1.1.

Any tips?

Could you post a picture of a network diagram of your setup?

It would be something like this i assume.

If you add debug nodes and set them to complete message object, you will see the _session object received.
e.g.

{"type":"tcp","id":"4069fb619d89bbf9"}

If you do not overwrite this object and make sure it gets to the out node, it should only reply to the incoming tcp connection.

You can read about this in the out nodes help text.

1 Like

I had already tried assigning the devices to diffrent ports and separate nodes like in the uploaded picture.
message

Injecting messages to port 999 will cause the upper connection (port 998) to receive the message too. I also tried moving them to separate flows, but that also didnt do anything.

Again add a debug to the tcp in node, set to full message object and look at the _session object. The _session object has to make it to the out node. It has nothing to do with port numbers.

2 Likes

I think i have found the mistake that i was making:
Injecting a msg directly into TCP Output without any session info resulted in it being sent to every active connection.

I have made a crude program that catches msg._session and sends a message using that session information, and it seems to work now - BUT i have a problem with extracting all the sessions and redirecting them to diffrent routes, so i can handle them individually.

If you post a export example flow, we can then give you some pointers.

How to import/export a flow

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

You can edit and correct your post by clicking the pencil :pencil2: icon.

See this post for more details - How to share code or flow json

No need, i will manage it somehow.
Thank you for your time and putting me on the right path.

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