Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket error after bind fails #24

Closed
dpjanes opened this issue Jan 10, 2016 · 2 comments
Closed

Socket error after bind fails #24

dpjanes opened this issue Jan 10, 2016 · 2 comments
Labels

Comments

@dpjanes
Copy link

dpjanes commented Jan 10, 2016

In node-lifx/lib/lifx/client.js if bind fails (say, because the address is in use) the error is emitted correctly. Unfortunately, later on socket.send will cause an exception during scanning because self.port is not set up correctly.

This can be fixed by moving this code

// Start scanning
if (opts.startDiscovery) {
  this.startDiscovery();
}

Inside the this.socket.bind block that immediately precedes it. e.g.

  this.socket.bind(opts.port, opts.address, function() {
    this.socket.setBroadcast(true);
    this.emit('listening');
    this.port = opts.port;
    if (typeof callback === 'function') {
      return callback();
    }

    // Start scanning
    if (opts.startDiscovery) {
      this.startDiscovery();
    }
  }.bind(this));
@dpjanes dpjanes changed the title Socket error which bind fails Socket error after bind fails Jan 10, 2016
@MariusRumpf
Copy link
Owner

Moving the start of scanning would solve this issue only part wise (if you do not use startDiscovery directly afterwards) . Say you use the startDiscovery and stopDiscovery methods directly then the error would still be thrown. We should integrate a check if the socket is bound to fix this.

@MariusRumpf
Copy link
Owner

Moving the start of scanning would also be correct in order of sending start. Should all be solved now and be part of the next release, thanks.

MariusRumpf added a commit that referenced this issue Mar 30, 2016
* develop:
  Check if socket is bound when sending packets #24
  Close client socket on error
  Document new settings in README
  New config option to set custom broadcast address
  Update tests and checks for accessing a bulb in a foreign network
  Bump dependencies
  Revert rolling over sequence number
  Adjust sequence expectations (reverted from commit 62d9a70)
  Adjust sequence expectations
  Fix travis errors
  Add documentation for lights
  Allow accessing a bulb in a foreign network
  Correct the product name for the Color BR30 bulb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants