Last active
August 29, 2015 14:02
-
-
Save JustinTW/cf7e10e152662e1b1146 to your computer and use it in GitHub Desktop.
udp multicast test
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
var PORT = 8088; | |
var HOST = '192.168.67.91'; | |
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.setBroadcast(true) | |
client.setMulticastTTL(128); | |
client.addMembership('230.185.192.108'); | |
}); | |
client.on('message', function (message, remote) { | |
console.log('A: Epic Command Received. Preparing Relay.'); | |
console.log('B: From: ' + remote.address + ':' + remote.port +' - ' + message); | |
}); | |
client.bind(PORT, HOST); |
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
var news = [ | |
"Borussia Dortmund wins German championship", | |
"Tornado warning for the Bay Area", | |
"More rain for the weekend", | |
"Android tablets take over the world", | |
"iPad2 sold out", | |
"Nation's rappers down to last two samples" | |
]; | |
var dgram = require('dgram'); | |
var server = dgram.createSocket("udp4"); | |
server.bind(8088, function(){ | |
server.setBroadcast(true); | |
server.setMulticastTTL(128); | |
server.addMembership('230.185.192.108'); | |
}); | |
setInterval(broadcastNew, 3000); | |
function broadcastNew() { | |
var message = new Buffer(news[Math.floor(Math.random()*news.length)]); | |
server.send(message, 0, message.length, 8088, "230.185.192.108"); | |
console.log("Sent " + message + " to the wire..."); | |
//server.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment