Skip to content

Instantly share code, notes, and snippets.

@reconbot
Created May 30, 2014 23:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reconbot/bea9c47c9c48d2aa7d8a to your computer and use it in GitHub Desktop.
Save reconbot/bea9c47c9c48d2aa7d8a to your computer and use it in GitHub Desktop.
var dgram = require('dgram');
// Make a udp socket
var socket = dgram.createSocket('udp4');
// Listen on a port on all addresses.
socket.bind(48879, function () {
socket.setBroadcast(true); // We intend to broadcast
});
// Let folks know what's up
socket.on('listening', function () {
console.log("# Now listening on port 48879");
});
// We get message, main screen turn on
socket.on('message', function (buffer) {
process.stdin.write("> " + buffer.toString());
});
process.stdin.write("# Sending messages to everyone port 48879\n");
process.stdin.on('data', function (message) {
socket.send(message, 0, message.length, 48879, '255.255.255.255');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment