Created
September 6, 2014 14:25
-
-
Save yorkie/2e37b182abccbedb7191 to your computer and use it in GitHub Desktop.
sends all devices with port(10000) in LAN
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 dgram = require('dgram'); | |
var assert = require('assert'); | |
var args = process.argv.slice(2); | |
var port = parseInt(args[0]); | |
assert.ok(typeof port === 'number'); | |
var dc = dgram.createSocket('udp4'); | |
dc.on('error', function(err) { | |
throw err; | |
}); | |
dc.on('message', function(msg, rinfo) { | |
console.log(arguments); | |
}); | |
dc.on('listening', function() { | |
var addr = dc.address(); | |
console.log('datacenter listening on: ' + addr.addr + ':' + addr.port); | |
after(); | |
}); | |
dc.bind(port); | |
function after() { | |
// ready for broadcast | |
var msg = new Buffer('beep'); | |
dc.setBroadcast(true); | |
dc.send(msg, 0, msg.length, 10000, '255.255.255.255', function(err, bytes) { | |
console.log(arguments); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment