1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const dgram = require('dgram'); 6 7{ 8 // Should throw EBADF if the socket is never bound. 9 const socket = dgram.createSocket('udp4'); 10 11 assert.throws(() => { 12 socket.setBroadcast(true); 13 }, /^Error: setBroadcast EBADF$/); 14} 15 16{ 17 // Can call setBroadcast() after binding the socket. 18 const socket = dgram.createSocket('udp4'); 19 20 socket.bind(0, common.mustCall(() => { 21 socket.setBroadcast(true); 22 socket.setBroadcast(false); 23 socket.close(); 24 })); 25} 26