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

Race condition on client.bind() and client.setBroadcast(true) #5

Open
stevecraig opened this issue Dec 13, 2013 · 2 comments
Open

Race condition on client.bind() and client.setBroadcast(true) #5

stevecraig opened this issue Dec 13, 2013 · 2 comments

Comments

@stevecraig
Copy link
Contributor

in index.js and lwrf-energy.js there is the following code:

  client.bind(9761);
  client.setBroadcast(true);

Due to known issues with dgram setBroadcast must only be called after bind (as done above) but bind is an async call.

On my laptop (Macbook - OSX) this consistently fails as bind has not completed by the time setBroadcast is called. I haven't observed this directly on the ninjablock but I have had intermittent failures which may be as a result.

The fix is simple (but I am writing it from memory as on different machine):

   client.on("listening", function() {
     client.setBroadcast(true);
     /* send message in here etc etc */
   });
   client.bind(); /* this will trigger the listening callback */

I can submit a push request for this later but thought I would raise the issue first (and I have been hacking my code to get everything working so need to tidy up)

@simonmcmanus
Copy link
Contributor

👍 - I noticed this too when running it on my laptop. Worked fine on the NinjaBlock though.

@mcmadhatter
Copy link
Owner

Hmm, never thought to try it on a non ninja device. Thanks for the info + future fix.I'll pick up when you submit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants