# Udp out node bind to local port

**URL:** https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636
**Category:** General
**Created:** [12 November 2021 14:03 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636 "2021-11-12T14:03:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![plouc](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@plouc](https://discourse.nodered.org/u/plouc)
#### Post date: [12 November 2021 14:03 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636/1 "2021-11-12T14:03:06Z")

</div>

Hello everyone,

In the process of understanding how SRT protocol works, I would like to pass the SRT trought nodered which is a tool i really appreciate to troubleshoot.

So it seems simple but might not be so.

The idea is to listen on a UDP port, be able to extract part of the data and resend it to the end user. Problem is i didn't find a way to change the binding of the port dynamicaly for the user to be able to respond correctly. I'm basically looking for msg.localport property which doesn't exists.

So do you think it could be possible to use JS function directly and be able to change the local binding port for every message.  
Thanks a lot for your help and the wunderful tool nodered is.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [12 November 2021 15:38 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636/2 "2021-11-12T15:38:46Z")

</div>

The UDP node does not say that you can send a message, so that means that you can't (assuming the docs are right). It probably binds to the port when node-red runs so it would require mods to the node to allow that.

You could use an environment variable which would mean you could set it externally, but it would require a node-red restart to use the changed env var.

---

<div class="post-metadata">

### Author: ![plouc](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@plouc](https://discourse.nodered.org/u/plouc)
#### Post date: [14 November 2021 07:14 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636/3 "2021-11-14T07:14:50Z")

</div>

Thanks Colin,

This is basically what I figured out. So i’ll Have to do it with js functions directly. Does anyone have an example on how to do it?

Thanks

---

<div class="post-metadata">

### Author: ![plouc](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@plouc](https://discourse.nodered.org/u/plouc)
#### Post date: [18 November 2021 06:55 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636/4 "2021-11-18T06:55:04Z")

</div>

If some wonders...  
it wass as simple as this:

```auto
const dgram = global.get('dgram');

const server = dgram.createSocket('udp4');

server.bind(msg.out_port);

server.send(msg.payload,msg.port,msg.ip, ()=> {
  server.close();});

return msg;

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [2 December 2021 06:55 UTC](https://discourse.nodered.org/t/udp-out-node-bind-to-local-port/53636/5 "2021-12-02T06:55:08Z")

</div>

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