jangxx / node-magichome

An incomplete implementation of the functionality of the "Magic Home" app. Partially a port of https://github.com/Danielhiversen/flux_led to Node.js
ISC License
124 stars 26 forks source link

Fixed device discovery on Windows #17

Closed martynaskre closed 5 years ago

jangxx commented 5 years ago

192.168.1.255 might be your local broadcast address, but that is in no way a universal solution. Like I said in my comment, you need to take a look at all the interface addresses and broadcast on every one of them. Sorry, but I can't merge this PR in the current state.

martynaskre commented 5 years ago

For example, to send a broadcast to all hosts on the network identified by IP addresses starting with 192.168.1, use the address 192.168.1.255.

As I understand its universal on Windows. Quote from here.

jangxx commented 5 years ago

The text you quoted explicitly says, that this only works for IP addresses starting with 192.168.1, which means that it does not work for any other addresses. If someones computer has the address 10.0.0.5 for example, sending a UDP packet to 192.168.1.255 would not work. That's what I meant when I said it's not universal. It might work for your configuration, but it wouldn't work for me for example, since my devices are on the 192.168.0.255 subnet.

martynaskre commented 5 years ago

I think the solution is to identify network address, for example if its 192.168.1.x or 192.168.0.x and add 255 in the end. I dont know much about networking, but it should be universal on Windows. What do you think?

jangxx commented 5 years ago

You probably have to do some workaround, by working with the output of os.networkInterfaces() and replacing the last bytes of the IP addresses or something.

This is exactly what I proposed two days ago and yes, I think this approach is the way to go.