From 942d2042fe25f143b3e4992cb04239d949009bac Mon Sep 17 00:00:00 2001 From: Luc Date: Tue, 5 Nov 2024 15:16:45 +0100 Subject: [PATCH] Resolving broadcast option within UDP Helper - Moved `setBroadcast(true)` into 'listening' event to better ensure that bind() has been completed successfully, resolving EBADF error --- src/helpers/udp.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/helpers/udp.ts b/src/helpers/udp.ts index d006ce0..a71d4ab 100644 --- a/src/helpers/udp.ts +++ b/src/helpers/udp.ts @@ -84,10 +84,6 @@ export class UDPHelper extends EventEmitter { ) } - if (this.#options.broadcast) { - this.#socket.setBroadcast(true) - } - if (this.#options.ttl !== undefined) { this.#socket.setTTL(this.#options.ttl) } @@ -110,6 +106,11 @@ export class UDPHelper extends EventEmitter { // } // } + // Needed to be called after bind() had completed + if (this.#options.broadcast) { + this.#socket.setBroadcast(true) + } + if (this.#options.multicast_interface) { this.#socket.setMulticastInterface(this.#options.multicast_interface) }