From 96406058b602dd19c40f073dfcd7700e3e50219e Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Fri, 27 Sep 2013 22:46:34 +0100 Subject: [PATCH 1/2] Remove silly address hack --- lib/client.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index bc0d53b..e0b563d 100644 --- a/lib/client.js +++ b/lib/client.js @@ -73,8 +73,6 @@ module.exports = function(options) { } } - addresses = [addresses[1]]; - // Performs broadcast discovery on each interface addresses.forEach(function(address) { // Sets up a broadcast socket From 5fffe14f93d13b36cc69899d7e55c14152890c1c Mon Sep 17 00:00:00 2001 From: "Robert (Jamie) Munro" Date: Fri, 27 Sep 2013 22:48:30 +0100 Subject: [PATCH 2/2] Bind is now async, moved things to callback --- lib/client.js | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/client.js b/lib/client.js index e0b563d..24a1571 100644 --- a/lib/client.js +++ b/lib/client.js @@ -77,20 +77,21 @@ module.exports = function(options) { addresses.forEach(function(address) { // Sets up a broadcast socket var socket = dgram.createSocket('udp4'); - socket.bind(self.localPorts.discovery, address); - socket.setBroadcast(true); - - // Sends the broadcast discover command - var buffer = commandManager.encode('broadcastDiscover', self.deviceSettings); - socket.send(buffer, 0, buffer.length, self.remotePorts.discovery, "255.255.255.255"); - socket.on('message', function(buffer, info) { - // Recieves the command and fulfills the promise - var response = commandManager.decode(buffer); - response.remoteAddress = info.address; - response.localAddress = address; - self.devices[response.serialNumber] = response; - deferred.resolve(response.serialNumber); - socket.close(); + socket.bind(self.localPorts.discovery, address, function () { + socket.setBroadcast(true); + + // Sends the broadcast discover command + var buffer = commandManager.encode('broadcastDiscover', self.deviceSettings); + socket.send(buffer, 0, buffer.length, self.remotePorts.discovery, "255.255.255.255"); + socket.on('message', function(buffer, info) { + // Recieves the command and fulfills the promise + var response = commandManager.decode(buffer); + response.remoteAddress = info.address; + response.localAddress = address; + self.devices[response.serialNumber] = response; + deferred.resolve(response.serialNumber); + socket.close(); + }); }); })