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

Multicast messages are not received unless this._udp.bind uses 0.0.0.0 instead of a specific interface. #97

Open
tyranno opened this issue Nov 25, 2024 · 0 comments

Comments

@tyranno
Copy link

tyranno commented Nov 25, 2024

Problem:
When using this._udp.bind(this._PORT, "192.168.x.x", ...) to bind the socket to a specific network interface, multicast messages are not received.
However, using tcpdump, it is confirmed that multicast packets are reaching the network interface.

Cause:
When binding to a specific network interface, the Node.js UDP socket sometimes fails to handle multicast packets properly in certain environments.
To ensure multicast traffic is received on all network interfaces, the socket must be bound to 0.0.0.0.

Solution:
Change the binding code to this._udp.bind(this._PORT, "0.0.0.0", ...) to allow multicast packets to be received on all interfaces.

Replace the current binding logic with the following:
this._udp.bind(this._PORT, "0.0.0.0", () => {
console.log(UDP socket bound to 0.0.0.0:${this._PORT});
this._udp.removeAllListeners('error');
this._sendProbe().then(() => {
console.log("Probe message sent successfully.");
}).catch((error) => {
console.error("Error sending probe:", error);
});
this._discovery_wait_timer = setTimeout(() => {
this.stopProbe().then(() => {
let device_list = [];
Object.keys(this._devices).forEach((urn) => {
device_list.push(this._devices[urn]);
});
console.log("Discovery complete, devices found:", device_list);
resolve(device_list);
}).catch((error) => {
console.error("Error stopping probe:", error);
reject(error);
});
}, this._DISCOVERY_WAIT);
});

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

1 participant