Tcp-in node "listen-to" mode: listen on non-localhost?

Hi There,

Just as followup on my tcp nodes question, I'm wondering is it possible to listen to something non-localhost:

That configuration is: Tcp in node should start a server on port 1231 on host localhost right?

What if I want to start a listener on 192.178.100.23 ? Is that possible?

I can connect to a specific server but I can't start a server on a specific host ip - what am I missing?

Cheers!

If I am not mistaken, it will use the primary interface, or first or something - not sure how the decision is made - it may listen on all interfaces actually?

But behind the scenes it's using the net class, which has a listen method, that allows to specify the address (interface)

So is it possible - yes, just needs a Feature Request to expose the ablity

const socket = net.createServer(...)
socket.listen(1231,'192.178.100.23')
socket.on('data', function(d){
  // Do stuff
})

/* etc etc */
1 Like

The node doesn't pass any IP address when opening the server socket, so binds to all available IP addresses on all interfaces.

It is not currently possible to bind to a specific IP/interface.

1 Like

ok, good to know - I would have assumed only localhost but that makes absolutely no sense (when I think about it).

:open_mouth: I find that weird that no one has wanted that feature - I mean it is really not unusual for servers to have multiple interfaces, basically every server has localhost and external interface but in that case binding to all interfaces makes no difference.

won't be that hard since everything is there - host configuration is only hidden if listen to is selected, so basically don't hide the input field! :wink: In fact, I can enter a host to connnect to, then switch to listen to and the host is still there in the configuration even if the field is hidden :wink:

on the other hand, I assume that if it's not been an issue in the past ten years, it ain't that important - unless you're like me and like to dissect nodes ...

EDIT: sorry forgot: thanks to both of you for the answers :+1:

2 Likes

I can’t check right now but you may be able to see where the incoming connection is coming from so even if all interfaces are allowed then you could filter if necessary. ( maybe )

1 Like

True, that's the case:

the ip value is the ip of the interface the tcp in node is connected to and not the ip of the incoming server.

I think that it would be reasonable to add an input to the node to allow restricting to a specific interface? Node-RED itself can be restricted via settings.js and it is good practice to only allow access on a specific interface.

exactly and that's why I asked whether that was possible with the tcp in node. I never thought of a global configuration for something that is relatively specific to the tcp in node.