Last active
March 14, 2017 22:30
-
-
Save max-mapper/0532dd0fda601396dc31361e54ddcab7 to your computer and use it in GitHub Desktop.
read multicast packets from node
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 socket = dgram.createSocket({ type: 'udp4', reuseAddr: true }) | |
socket.bind(5004, function () { | |
socket.addMembership('239.255.42.42', getIpForInterface('en2')) | |
socket.setMulticastTTL(255) | |
}) | |
socket.on('message', function (m) { | |
// m is a buffer | |
}) | |
function getIpForInterface (ifname) { | |
return os.networkInterfaces()[ifname].reduce(function (i, j) { | |
if (i.family === 'IPv4') return i | |
return j | |
}).address | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment