discover() {
        let promiseResponded = false;
        return new Promise((resolve, reject) => {
            this.socket = dgram.createSocket({type: 'udp4', reuseAddr: true});

            this.socket.on('message', (message, remote) => {
                this._parseResponse(message, remote);
            });

            this.socket.on('error', err => {
                debug('Can not Listen for UDP packages: ' + err);
                if (!promiseResponded) {
                    reject(err);
                    promiseResponded = true;
                }
                this.emit('error', err);
            });

            this.socket.bind(undefined, this.options.listenAddress || '0.0.0.0', () => {
                if (!this.socket) {
                    return;
                }
                debug('Listen for local PH803W devices on port 12414');

                try {
                    this.socket.setBroadcast(true);
                } catch (e) {
                    this.socket.emit('error', e);
                }

                const probeData = Buffer.from('0000000303000003', 'hex');
                debug(`Send broadcast message ${probeData.toString('hex')}`);
                try {
                    this.socket.send(probeData, 0, probeData.length, PH803W_UDP_PORT, '255.255.255.255');
                } catch (e) {
                    this.socket.emit('error', e);
                }

                if (!promiseResponded) {
                    resolve(true);
                    promiseResponded = true;
                }
            });
        });
    }
/**
     * Start UDP Discovery server and start discovering devices
     * Event "device" is emitted when a device responds. One IP can be discovered multiple times!
     *
     * @returns {Promise<boolean>}
     */
Start UDP Discovery server and start discovering devices
Event "device" is emitted when a device responds. One IP can be discovered multiple times!

@returns {Promise}
Start UDP Discovery server and start discovering devices Event " device " is emitted when a device responds . One IP can be discovered multiple times! @returns { Promise }
discover() {
        let promiseResponded = false;
        return new Promise((resolve, reject) => {
            this.socket = dgram.createSocket({type: 'udp4', reuseAddr: true});
            this.socket.on('message', (message, remote) => {
                this._parseResponse(message, remote);
            });
            this.socket.on('error', err => {
                debug('Can not Listen for UDP packages: ' + err);
                if (!promiseResponded) {
                    reject(err);
                    promiseResponded = true;
                }
                this.emit('error', err);
            });
            this.socket.bind(undefined, this.options.listenAddress || '0.0.0.0', () => {
                if (!this.socket) {
                    return;
                }
                debug('Listen for local PH803W devices on port 12414');
                try {
                    this.socket.setBroadcast(true);
                } catch (e) {
                    this.socket.emit('error', e);
                }
                const probeData = Buffer.from('0000000303000003', 'hex');
                debug(`Send broadcast message ${probeData.toString('hex')}`);
                try {
                    this.socket.send(probeData, 0, probeData.length, PH803W_UDP_PORT, '255.255.255.255');
                } catch (e) {
                    this.socket.emit('error', e);
                }
                if (!promiseResponded) {
                    resolve(true);
                    promiseResponded = true;
                }
            });
        });
    }
discover ( ) { let promiseResponded = false ; return new Promise ( ( resolve , reject ) => { this . socket = dgram . createSocket ( { type : 'udp4' , reuseAddr : true } ) ; this . socket . on ( 'message' , ( message , remote ) => { this . _parseResponse ( message , remote ) ; } ) ; this . socket . on ( 'error' , err => { debug ( 'Can not Listen for UDP packages: ' + err ) ; if ( ! promiseResponded ) { reject ( err ) ; promiseResponded = true ; } this . emit ( 'error' , err ) ; } ) ; this . socket . bind ( undefined , this . options . listenAddress || '0.0.0.0' , ( ) => { if ( ! this . socket ) { return ; } debug ( 'Listen for local PH803W devices on port 12414' ) ; try { this . socket . setBroadcast ( true ) ; } catch ( e ) { this . socket . emit ( 'error' , e ) ; } const probeData = Buffer . from ( '0000000303000003' , 'hex' ) ; debug ( ` ${ probeData . toString ( 'hex' ) } ` ) ; try { this . socket . send ( probeData , 0 , probeData . length , PH803W_UDP_PORT , '255.255.255.255' ) ; } catch ( e ) { this . socket . emit ( 'error' , e ) ; } if ( ! promiseResponded ) { resolve ( true ) ; promiseResponded = true ; } } ) ; } ) ; }
Start UDP Discovery server and start discovering devices
 Event "device" is emitted when a device responds.
Start UDP Discovery server and start discovering devices Event " device " is emitted when a device responds .