UDP out node set msg.localport

I am running node red on an ubuntu server and I have configured one of the network adapters to have several IP addresses, like this:

      dhcp4: true
       dhcp4: no
  version: 2

The idea is that I want to use node red to simulate several controllers, the different IP addresses corresponds to the controllers IP addresses.

In node red I am using an UDP out node to send packets and respond to heartbeat communication but I have not figured out a way to specifically send packets from for example IP I have read something about using the bind call to specify source address but I have not managed to figure out how it works.

I found this post but I don't understand and if I try to code I get this error: TypeError: Cannot read properties of undefined (reading 'createSocket')

The post you're referring to, fails to mention the need to expose the dgram module to function nodes

You do this in settings.js of Node RED

  /** The following property can be used to set predefined values in Global Context.
     * This allows extra node modules to be made available with in Function node.
     * For example, the following:
     *    functionGlobalContext: { os:require('os') }
     * will allow the `os` module to be accessed in a Function node using:
     *    global.get("os")
    functionGlobalContext: {
        // os:require('os'),

So for you....

functionGlobalContext: {

You can then use the code snippet from that post in function nodes.
Remember to restart Node RED after modifying the settings file.

1 Like

Much easier to add dgram to the function node setup tab these days.