Skip to content

Instantly share code, notes, and snippets.

@timothylhuillier
Last active August 29, 2015 14:21
Show Gist options
  • Save timothylhuillier/f93c28c82d6f695c5bb7 to your computer and use it in GitHub Desktop.
Save timothylhuillier/f93c28c82d6f695c5bb7 to your computer and use it in GitHub Desktop.
Broadcast LMS
var dgram = require('dgram');
var socket = dgram.createSocket('udp4');
var message = new Buffer([0x65,
'I', 'P', 'A', 'D', 0x00,
'N','A', 'M', 'E', 0x00,
'J', 'S', 'O', 'N', 0x00,
'V', 'E', 'R', 'S', 0x00,
'U', 'U', 'I', 'D', 0x00,
'J', 'V', 'I', 'D', 0x1,0x2,0x3,0x4,0x5,0x6,0x7]);
var broadcastAddress = '255.255.255.255';
// Port utilisé pour le broadcast et SlimProto
var broadcastPort = 3483;
socket.on("listening", function() {
console.log("socket openned");
socket.setBroadcast(true);
});
socket.on("message", function ( data, rinfo ) {
console.log("Message received from ", rinfo.address, " : ", data);
});
setInterval(function () {
socket.send(new Buffer(message),
0,
message.length,
broadcastPort,
broadcastAddress,
function (err) {
if (err) console.log(err);
console.log("Message sent");
}
);
}, 1000);
# udpClient node client.js
socket openned
Message sent
Message received from 10.251.98.134 : <Buffer 45>
Message received from 10.251.98.175 : <Buffer 45>
Message sent
Message received from 10.251.98.134 : <Buffer 45>
Message sent
Message received from 10.251.98.134 : <Buffer 45>
Message sent
Message received from 10.251.98.134 : <Buffer 45>
Message received from 10.251.98.175 : <Buffer 45>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment