Created
February 24, 2016 05:57
-
-
Save vartana/2598d59e5730f5aae0c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
CLIENT: | |
var SRC_PORT = 6025; | |
var PORT = 6024; | |
var MULTICAST_ADDR = '239.255.255.250'; | |
var dgram = require('dgram'); | |
var server = dgram.createSocket("udp4"); | |
server.bind(SRC_PORT, function () { | |
setInterval(multicastNew, 4000); | |
}); | |
function multicastNew() { | |
var message = new Buffer("Multicast message!"); | |
server.send(message, 0, message.length, PORT, MULTICAST_ADDR, function () { | |
console.log("Sent '" + message + "'"); | |
}); | |
} | |
SERVER: | |
var PORT = 6024; | |
var MULTICAST_ADDR = '239.255.255.250'; | |
var dgram = require('dgram'); | |
var client = dgram.createSocket('udp4'); | |
client.on('listening', function () { | |
var address = client.address(); | |
console.log('UDP Client listening on ' + address.address + ":" + address.port); | |
}); | |
client.on('message', function (message, rinfo) { | |
console.log('Message from: ' + rinfo.address + ':' + rinfo.port + ' - ' + message); | |
}); | |
client.bind(PORT, function () { | |
client.addMembership(MULTICAST_ADDR); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment