coming from this page, https://nodejs.org/api/dgram.html#class-dgramsocket I took over this example:
const dgram = require('dgram');
const server = dgram.createSocket('udp4');
server.on('error', (err) => {
console.log(`server error:\n${err.stack}`);
server.close();
});
server.on('message', (msg, rinfo) => {
console.log(`server got: ${msg} from ${rinfo.address}:${rinfo.port}`);
});
server.on('listening', () => {
const address = server.address();
console.log(`server listening ${address.address}:${address.port}`);
});
server.bind(41234);
// Prints: server listening 0.0.0.0:41234
server.bind() would also work, then it takes a free port I guess.
But the example is not working , the clients response to 0.0.0.0 would not get received on this host.
So I chage to
server.bind(65000, "192.168.0.1");
But together with IP the interfaces forces me to specify a port. How can I omit this?
Thanks