Created
August 27, 2012 16:23
-
-
Save mdodsworth/3490042 to your computer and use it in GitHub Desktop.
node: multicast example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dgram = require('dgram'); | |
var socket = dgram.createSocket('udp4'); | |
var testMessage = "[hello world] pid: " + process.pid; | |
var multicastAddress = '239.1.2.3'; | |
var multicastPort = 5554; | |
socket.bind(multicastPort, '0.0.0.0'); | |
socket.addMembership(multicastAddress); | |
socket.on("message", function ( data, rinfo ) { | |
console.log("Message received from ", rinfo.address, " : ", data.toString()); | |
}); | |
setInterval(function () { | |
socket.send(new Buffer(testMessage), | |
0, | |
testMessage.length, | |
multicastPort, | |
multicastAddress, | |
function (err) { | |
if (err) console.log(err); | |
console.log("Message sent"); | |
} | |
); | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working: