My program throw an EACCES error when execute send() method of dgram.udp4 socket, but only does it on Windows.
The code:
var dgram = require('dgram');
var monsocket = dgram.createSocket("udp4");
monsocket.on("listening", function () { comBroadcastCallUp(); });
var comBroadcastCallUp = function() {
var message = new Buffer(JSON.stringify({
protocol: "psdp",
command: "call-up"
}));
monsocket.setBroadcast(true);
monsocket.send(message, 0, message.length, 32681, '255.255.255.255', function (err) {
if (err) console.log(err)
else console.log("<PcStatus:PSDP> Message sent: " + message + os.EOL + "Message length: " + message.length);
});
monsocket.setBroadcast(false);
}
monsocket.bind(32681);
Same code, terminal output on Windows:
{ [Error: send EACCES] code: 'EACCES', errno: 'EACCES', syscall: 'send' }
Terminal output on Linux:
<PcStatus:PSDP> Message sent: {"protocol":"psdp","command":"call-up"}
Message length: 39
I check the firewall, if other program kept the port busy, nothing...
Broadcasting to 255.255.255.255 is not supported anymore as of Windows 7 I believe. You will need to limit the send to a particular subnet instead.
Also keep in mind that not all routers will route packets destined for 255.255.255.255.