Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
Creating multiple UDP servers for listening to broadcast messages on NodeJS

I need to have a UDP server that is able to listen to broadcast messages and reply with a message containing my machine's IP address (the broadcast sender expects my IP to be on the body of the message).

If I bind the server to all available interfaces (by providing only the port) I'm perfectly able to receive broadcasts, like so:

const dgram = require('dgram');

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

server.on('message', (msg, rinfo) => {
    console.log(msg.toString())
    // I need to send my IP address here with server.send()
})

server.bind(44818, () => {
    console.log(`Server created at ${server.address().address}`)
})

The problem is that server.address().address returns 0.0.0.0, so I'm unable to return a valid/reachable IP address.

I tried creating one UDP server manually for each available interface on my machine:

const dgram = require('dgram');
const os = require('os');

const interfaces = os.networkInterfaces()

for (const interface in interfaces) {
    if (interface !== 'lo') {
        const server = dgram.createSocket('udp4');

        server.on('message', (msg, rinfo) => {
            console.log(msg.toString())
        })

        server.bind(44818, interfaces[interface][0].address, () => {
            console.log(`Server created at ${server.address().address} (${interface})`)
        })
    }
}

Now server.address().address returns the specific IP address that each server is bound to, but for some reason I'm now unable to receive broadcast messages i.e. the 'message' event is never called.

Any suggestions on how I could do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!