# UDP Out Node is not bound to correct port number

**URL:** <https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754>\
**Category:** General\
**Created:** [12 June 2018 01:43 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754 "2018-06-12T01:43:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![pauldeng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pauldeng/32/574_2.png) [@pauldeng](https://discourse.nodered.org/u/pauldeng)\
**Post date:** [12 June 2018 01:43 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/1 "2018-06-12T01:43:47Z")

</div>

Hi all,

I am new to this. So please forgive me if I ask a silly question.

I created a simple UDP ping-pong function:  
1. Endpoint A (port 3000) sends a Ping to Endpoint B (port 3001)  
2. Endpoint B (port 3001) replies a Pong to Endpoint A (port 3000)

 ![chrome_2018-06-12_11-38-22](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/a3e4766573a0f618f77aa6ffe009dc44efa7f634.png)

`[{"id":"725b7ffb.59aa","type":"inject","z":"e559e2e2.79d9a","name":"Send Ping","topic":"","payload":"Ping","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":1760,"wires":[["c9181d5.3ccece"]]},{"id":"6fe3ee5a.ffadf","type":"udp out","z":"e559e2e2.79d9a","name":"Send from port 3000","addr":"","iface":"","port":"","ipv":"udp4","outport":"3000","base64":false,"multicast":"false","x":920,"y":1700,"wires":[]},{"id":"71434c52.25bea4","type":"udp in","z":"e559e2e2.79d9a","name":"Listen on port 3000","iface":"","port":"3000","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":110,"y":1600,"wires":[["8cdf279f.2a9148","ed3ba85b.cea8b8"]]},{"id":"8cdf279f.2a9148","type":"debug","z":"e559e2e2.79d9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":390,"y":1560,"wires":[]},{"id":"ed3ba85b.cea8b8","type":"delay","z":"e559e2e2.79d9a","name":"Delay 5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":1640,"wires":[["c9181d5.3ccece"]]},{"id":"ea6dce7b.5d07d","type":"inject","z":"e559e2e2.79d9a","name":"Send Pong","topic":"","payload":"Pong","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":2200,"wires":[["7ddf4466.e25d7c"]]},{"id":"93f14deb.fb968","type":"udp out","z":"e559e2e2.79d9a","name":"Send from port 3001","addr":"","iface":"","port":"","ipv":"udp4","outport":"3001","base64":false,"multicast":"false","x":840,"y":2140,"wires":[]},{"id":"f002937.fa9307","type":"udp in","z":"e559e2e2.79d9a","name":"Listen on port 3001","iface":"","port":"3001","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":110,"y":2020,"wires":[["63d71c31.13bf34","ef120942.f7ef88"]]},{"id":"63d71c31.13bf34","type":"debug","z":"e559e2e2.79d9a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":390,"y":1960,"wires":[]},{"id":"ef120942.f7ef88","type":"delay","z":"e559e2e2.79d9a","name":"Delay 5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":400,"y":2080,"wires":[["7ddf4466.e25d7c"]]},{"id":"c9181d5.3ccece","type":"function","z":"e559e2e2.79d9a","name":"To Endpoint B on port 3001","func":"msg.ip = \"localhost\";\nmsg.port = 3001;\nreturn msg;","outputs":1,"noerr":0,"x":640,"y":1700,"wires":[["6fe3ee5a.ffadf"]]},{"id":"7ddf4466.e25d7c","type":"function","z":"e559e2e2.79d9a","name":"Reply with Pong","func":"let message = {\"ip\":msg.ip, \"port\": msg.port, \"payload\": \"Pong\"}\nreturn message;","outputs":1,"noerr":0,"x":600,"y":2140,"wires":[["93f14deb.fb968"]]},{"id":"2c812ae9.c673d6","type":"comment","z":"e559e2e2.79d9a","name":"Endpoint A","info":"","x":80,"y":1560,"wires":[]},{"id":"a21bd587.ca1008","type":"comment","z":"e559e2e2.79d9a","name":"Endpoint B","info":"","x":80,"y":1980,"wires":[]}]`

I expect Endpoint A receives a Pong from Endpoint B (port 3001) which is specified in Endpoint B's UDP Out. However, Endpoint A actually shows Pong is from port 3000 which is wrong. What did I do wrong?

Node Red: 0.18.7  
Nodejs: 8.11.2  
OS: Ubuntu 16.04

Thanks for help.

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)\
**Post date:** [12 June 2018 09:50 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/2 "2018-06-12T09:50:20Z")

</div>

Hello Paul

I have some know-how in networking. In my view it is not useful to set the sending port in the UDP out nodes. Leave it to the OS to decide, therefore set the config to ‘random’.

I have crappy know-how in Javascript. The first function node seems to work. The Ping gets out. But the second function node ‘eats’ the incoming message, nothing gets out. Therefore I strongly suggest to just copy the code from the one above, since it works.  
BTW: the change node does the same thing, you do not need a function node for what you want to achieve.

Kind regards,

Urs.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [12 June 2018 11:47 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/3 "2018-06-12T11:47:29Z")

</div>

Indeed, it is like Urs said. The "ping" string in msg.payload gets lost as it is not reconfigured by the first function node. The "pong" keeps circulating forever. Amending the function code fixes the issue. Therefore nothing seems wrong with UDP port assignment and use.

```auto
msg.ip = "localhost";
msg.port = 3001;
msg.payload = "ping";
return msg;

```

Before:

 ![ping-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/64992232d10cbea826c796113a88c84120705b20.PNG)

After (click the picture to enlarge) :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/1e72a5c4aba531e205a4161bdec301092ab00235.png)

---

<div class="post-metadata">

**Author:** ![pauldeng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pauldeng/32/574_2.png) [@pauldeng](https://discourse.nodered.org/u/pauldeng)\
**Post date:** [13 June 2018 23:54 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/4 "2018-06-13T23:54:11Z")

</div>

Hi Urs and Andrei,

Thanks a lot for your reply.

Andrei, I made the changes you mentioned. But unlike yours, my node red still shows that Pong message is sent from port 3000 (which should be 3001).  
 ![chrome_2018-06-14_09-52-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/7ea23da3d0a37d31484b85cab7610dc87e795e22.png)

Can I ask what is your OS, nodejs and node-red version?

Thanks a lot!

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 June 2018 03:22 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/5 "2018-06-14T03:22:12Z")

</div>

Hello Paul,

Really interesting (and puzzling). Perhaps something specific to the OS ?

Here my configuration:

14 Jun 00:13:01 - [info] Node-RED version: v0.18.4  
14 Jun 00:13:01 - [info] Node.js version: v8.11.1  
14 Jun 00:13:01 - [info] Windows\_NT 10.0.17134 x64 LE

What happens if you fix the destination ports in both UDP output nodes ? Like below for instance ?

![udp-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/a951cbc1ebea445bf95c3364bfda455e2eecc9bb.PNG)

the code I test (just in case):

```auto
[{"id":"1b03db00.66de75","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"c9229d.46030d6","type":"inject","z":"1b03db00.66de75","name":"Send Ping","topic":"","payload":"Ping","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":422.50001525878906,"y":290.00000762939453,"wires":[["53f754c1.c89fbc"]]},{"id":"4394e591.ad717c","type":"udp out","z":"1b03db00.66de75","name":"Send from port 3000","addr":"","iface":"","port":"","ipv":"udp4","outport":"3000","base64":false,"multicast":"false","x":942.5000152587891,"y":230.00000762939453,"wires":[]},{"id":"865c646e.e911d8","type":"udp in","z":"1b03db00.66de75","name":"Listen on port 3000","iface":"","port":"3000","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":132.50001525878906,"y":130.00000762939453,"wires":[["c9b498fe.0b81f8","5c9bc1e6.6d33f"]]},{"id":"c9b498fe.0b81f8","type":"debug","z":"1b03db00.66de75","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":412.50001525878906,"y":90.00000762939453,"wires":[]},{"id":"5c9bc1e6.6d33f","type":"delay","z":"1b03db00.66de75","name":"Delay 5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":373.50000762939453,"y":164.00001430511475,"wires":[["53f754c1.c89fbc"]]},{"id":"d68c1e8d.fdd5a","type":"inject","z":"1b03db00.66de75","name":"Send Pong","topic":"","payload":"Pong","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":422.50001525878906,"y":730.0000076293945,"wires":[["ddce1a7b.0987d8"]]},{"id":"357fdcf3.b41de4","type":"udp out","z":"1b03db00.66de75","name":"Send from port 3001","addr":"","iface":"","port":"","ipv":"udp4","outport":"3001","base64":false,"multicast":"false","x":862.5000152587891,"y":670.0000076293945,"wires":[]},{"id":"c812eac6.7eb388","type":"udp in","z":"1b03db00.66de75","name":"Listen on port 3001","iface":"","port":"3001","ipv":"udp4","multicast":"false","group":"","datatype":"utf8","x":132.50001525878906,"y":550.0000076293945,"wires":[["f2f3978.792d468","189ce106.e5af9f"]]},{"id":"189ce106.e5af9f","type":"debug","z":"1b03db00.66de75","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":412.50001525878906,"y":490.00000762939453,"wires":[]},{"id":"f2f3978.792d468","type":"delay","z":"1b03db00.66de75","name":"Delay 5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":422.50001525878906,"y":610.0000076293945,"wires":[["ddce1a7b.0987d8"]]},{"id":"53f754c1.c89fbc","type":"function","z":"1b03db00.66de75","name":"To Endpoint B on port 3001","func":"msg.ip = \"localhost\";\nmsg.port = 3001;\nmsg.payload = \"ping\";\nreturn msg;","outputs":1,"noerr":0,"x":662.5000152587891,"y":230.00000762939453,"wires":[["4394e591.ad717c"]]},{"id":"ddce1a7b.0987d8","type":"function","z":"1b03db00.66de75","name":"Reply with Pong","func":"let message = {\"ip\":msg.ip, \"port\": msg.port, \"payload\": \"pong\"}\nreturn message;","outputs":1,"noerr":0,"x":622.5000152587891,"y":670.0000076293945,"wires":[["357fdcf3.b41de4"]]},{"id":"d07d24f8.f12dc8","type":"comment","z":"1b03db00.66de75","name":"Endpoint A","info":"","x":102.50001525878906,"y":90.00000762939453,"wires":[]},{"id":"a4e9e294.cc4f8","type":"comment","z":"1b03db00.66de75","name":"Endpoint B","info":"","x":102.50001525878906,"y":510.00000762939453,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [14 June 2018 05:22 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/6 "2018-06-14T05:22:58Z")

</div>

Paul,

I broght back to life an SBC, configured with Ubuntu ( 14.04.3), that was unused for nearly 3 years (just for testing UDP).

As you can imagine the Node-RED and the Node.JS are quite old.

14 Jun 14:40:49 - [info] Node-RED version: v0.13.1  
14 Jun 14:40:49 - [info] Node.js version: v4.2.6

I tested your flow, using only hard-coded ports in the configuration node (therefore not using msg.ip and msg.port for that purpose). The results are a surprise for me. The communication simply does not occur when I configure the UDP output bound to the same port as the UDP input node, like pictured below:

 ![udp-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/30767a3cf6d4af31a25a94ba20c309a43c8ca296.PNG)

When I bound a different UDP port for each flow (therefore 4 different UDP ports) it worked well.

 ![udp-03](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/bceb69a9068f5e28adc0e2678cb42673bedd595f.PNG)

Honestly speaking I don't know very well how the port binding works in linux but I thought it was legitimate to use the same UDP port for listening and for sending messages.

The very same config that is not working in Ubuntu is working on windows. I got an warning in the debug side panel (like below) but the communication works.

![udp-04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/c67478778f1373ca0c9c75cb4adb31425872c4d2.PNG)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 June 2018 06:17 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/7 "2018-06-14T06:17:54Z")

</div>

Thee have been several fixes to do with port binding since version 0.13  
Please upgrade

---

<div class="post-metadata">

**Author:** ![pauldeng](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/pauldeng/32/574_2.png) [@pauldeng](https://discourse.nodered.org/u/pauldeng)\
**Post date:** [15 June 2018 06:26 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/9 "2018-06-15T06:26:43Z")

</div>

Hi all,

I have done some test using [Andrei’s code](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/5?u=pauldeng) with different version Node-Red, here is the result:

- v0.18.7: buggy, Endpoint B sends messages from port 3000 (3001 expected)
- v0.18.6: buggy, As Above
- v0.18.5: buggy, As Above
- v0.18.4: No Issue, Endpoint B sends messages from port 3001
- v0.18.3: No Issue, As Above

Probably introduced in 0.18.5. I suspect was this issue: [https://github.com/node-red/node-red/pull/1686](https://github.com/node-red/node-red/pull/1686)

My envitonment:  
Nodejs: 8.11.3  
OS: Ubuntu 16.04

I will create a issue in github for this.

Thanks for all help!

Cheers,  
Paul

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 June 2018 09:10 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/10 "2018-06-15T09:10:57Z")

</div>

yes please. Does indeed look like a bug.

---

<div class="post-metadata">

**Author:** ![emlarsen](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emlarsen/32/889_2.png) [@emlarsen](https://discourse.nodered.org/u/emlarsen)\
**Post date:** [20 February 2020 21:10 UTC](https://discourse.nodered.org/t/udp-out-node-is-not-bound-to-correct-port-number/754/11 "2020-02-20T21:10:59Z")

</div>

I have seen similar behavior. It seems that you need the upd out and the udp in on different flows to get it to work
