# "UDP in" setting port dynamically

**URL:** <https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839>\
**Category:** General\
**Created:** [18 January 2022 07:14 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839 "2022-01-18T07:14:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![wepa](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@wepa](https://discourse.nodered.org/u/wepa)\
**Post date:** [18 January 2022 07:14 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/1 "2022-01-18T07:14:44Z")

</div>

Online help says:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/6/06971386cfce77362de18237e6afbc07814e7fba.png)

However, the node does not consider a msg.port variable (unlike "UDP out").

Is there any workaround for that(?)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 January 2022 07:55 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/2 "2022-01-18T07:55:50Z")

</div>

msg.ip and msg.port are output variables, from the UDP in node. You can not set port and ip dynamically with them

---

<div class="post-metadata">

**Author:** ![wepa](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@wepa](https://discourse.nodered.org/u/wepa)\
**Post date:** [18 January 2022 09:28 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/3 "2022-01-18T09:28:14Z")

</div>

for me it seems as if they are variables for the "udp out".  
I would like to use them for the "udp in" as also mentioned in the online help but this unfortunately doesn't work ☹

---

<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:** [18 January 2022 12:04 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/4 "2022-01-18T12:04:31Z")

</div>

> [@wepa](#):
>
> I would like to use them for the "udp in" as also mentioned in the online help

I cannot see that mentioned in the online help. It says:  
" It also provides `msg.ip` and `msg.port` set to the ip address and port from which the message was received."  
Which means that the node outputs those values. Not that you can pass them in to the node.

---

<div class="post-metadata">

**Author:** ![wepa](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@wepa](https://discourse.nodered.org/u/wepa)\
**Post date:** [18 January 2022 12:47 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/5 "2022-01-18T12:47:07Z")

</div>

yes, you are right.  
Now I also see that this is the meaning of this sentence ☹

It is really a pity that "udp out" supports this flexible handling and "udp in" not...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 January 2022 13:12 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/6 "2022-01-18T13:12:29Z")

</div>

Why do you want to set it dynamically? for end user configuration? other reason?

Would an env variable for the port number suffice?

You can use ${ENV\_VAR} in place of a port number if you wish.

[https://nodered.org/docs/user-guide/environment-variables](https://nodered.org/docs/user-guide/environment-variables)

---

<div class="post-metadata">

**Author:** ![wepa](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@wepa](https://discourse.nodered.org/u/wepa)\
**Post date:** [18 January 2022 14:02 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/7 "2022-01-18T14:02:03Z")

</div>

I have to connect to a unit which can work with different port-numbers so I want to configure the port-number in the dashboard.  
Can I also use flow or global variables in place of a port number within the "udp" node (?)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 January 2022 14:18 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/8 "2022-01-18T14:18:47Z")

</div>

> [@wepa](#):
>
> Can I also use flow or global variables in place of a port number within the "udp" node (?)

No. Your only options are

- static fixed number
- Environment variable (changes only take affect after node-red startup)
- Request to the author to add functionality
- fork the node and add the capability yourself

---

<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:** [19 March 2022 14:18 UTC](https://discourse.nodered.org/t/udp-in-setting-port-dynamically/56839/9 "2022-03-19T14:18:58Z")

</div>

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