Created
May 30, 2014 23:20
-
-
Save reconbot/bea9c47c9c48d2aa7d8a to your computer and use it in GitHub Desktop.
This file contains 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'); | |
// 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