'use strict'; var dgram = require('dgram'); var socket = dgram.createSocket({ type: 'udp4' , reuseAddr: true }); var dns = require('dns-js'); //var DNSPacket = dns.DNSPacket; var broadcast = '224.0.0.251'; // mdns var port = 5353; // mdns socket.on('message', function (message, rinfo) { console.log('Received %d bytes from %s:%d\n', message.length, rinfo.address, rinfo.port); //console.log(msg.toString('utf8')); message.forEach(parseInt(byte.toString('hex'), 16).toString(2)); console.log(message.toString('hex')); var packets; try { packets = dns.DNSPacket.parse(message); } catch (er) { //partial, skip it console.error(er); return; } if (!Array.isArray(packets)) { packets = [packets]; } require('./cloud-respond.js').respond(socket, packets, rinfo); }); socket.bind(port, function () { console.log('bound on', port); console.log('bound on', this.address()); socket.setBroadcast(true); socket.addMembership(broadcast); // buf.forEach parseInt(byte.toString('hex'), 16).toString(2); });