@@ -108,6 +108,9 @@ Tells the kernel to join a multicast group at the given `multicastAddress` and
108108one interface and will add membership to it. To add membership to every
109109available interface, call ` addMembership ` multiple times, once per interface.
110110
111+ When called on an unbound socket, this method will implicitly bind to a random
112+ port, listening on all interfaces.
113+
111114When sharing a UDP socket across multiple ` cluster ` workers, the
112115` socket.addMembership() ` function must be called only once or an
113116` EADDRINUSE ` error will occur:
@@ -141,6 +144,9 @@ is not specified, the operating system will choose one interface and will add
141144membership to it. To add membership to every available interface, call
142145` socket.addSourceSpecificMembership() ` multiple times, once per interface.
143146
147+ When called on an unbound socket, this method will implicitly bind to a random
148+ port, listening on all interfaces.
149+
144150### ` socket.address() `
145151<!-- YAML
146152added: v0.1.99
@@ -152,6 +158,8 @@ Returns an object containing the address information for a socket.
152158For UDP sockets, this object will contain ` address ` , ` family ` and ` port `
153159properties.
154160
161+ This method throws ` EBADF ` if called on an unbound socket.
162+
155163### ` socket.bind([port][, address][, callback]) `
156164<!-- YAML
157165added: v0.1.99
@@ -296,8 +304,9 @@ added: v12.0.0
296304-->
297305
298306A synchronous function that disassociates a connected ` dgram.Socket ` from
299- its remote address. Trying to call ` disconnect() ` on an already disconnected
300- socket will result in an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception.
307+ its remote address. Trying to call ` disconnect() ` on an unbound or already
308+ disconnected socket will result in an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ]
309+ exception.
301310
302311### ` socket.dropMembership(multicastAddress[, multicastInterface]) `
303312<!-- YAML
@@ -340,13 +349,17 @@ added: v8.7.0
340349
341350* Returns: {number} the ` SO_RCVBUF ` socket receive buffer size in bytes.
342351
352+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
353+
343354### ` socket.getSendBufferSize() `
344355<!-- YAML
345356added: v8.7.0
346357-->
347358
348359* Returns: {number} the ` SO_SNDBUF ` socket send buffer size in bytes.
349360
361+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
362+
350363### ` socket.ref() `
351364<!-- YAML
352365added: v0.9.1
@@ -373,8 +386,8 @@ added: v12.0.0
373386* Returns: {Object}
374387
375388Returns an object containing the ` address ` , ` family ` , and ` port ` of the remote
376- endpoint. It throws an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception if the
377- socket is not connected.
389+ endpoint. This method throws an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception
390+ if the socket is not connected.
378391
379392### ` socket.send(msg[, offset, length][, port][, address][, callback]) `
380393<!-- YAML
@@ -444,6 +457,8 @@ the error is emitted as an `'error'` event on the `socket` object.
444457Offset and length are optional but both * must* be set if either are used.
445458They are supported only when the first argument is a ` Buffer ` or ` Uint8Array ` .
446459
460+ This method throws [ ` ERR_SOCKET_BAD_PORT ` ] [ ] if called on an unbound socket.
461+
447462Example of sending a UDP packet to a port on ` localhost ` ;
448463
449464``` js
@@ -524,6 +539,8 @@ added: v0.6.9
524539Sets or clears the ` SO_BROADCAST ` socket option. When set to ` true ` , UDP
525540packets may be sent to a local interface's broadcast address.
526541
542+ This method throws ` EBADF ` if called on an unbound socket.
543+
527544### ` socket.setMulticastInterface(multicastInterface) `
528545<!-- YAML
529546added: v8.6.0
@@ -550,6 +567,8 @@ also use explicit scope in addresses, so only packets sent to a multicast
550567address without specifying an explicit scope are affected by the most recent
551568successful use of this call.
552569
570+ This method throws ` EBADF ` if called on an unbound socket.
571+
553572#### Example: IPv6 outgoing multicast interface
554573
555574On most systems, where scope format uses the interface name:
@@ -612,6 +631,8 @@ added: v0.3.8
612631Sets or clears the ` IP_MULTICAST_LOOP ` socket option. When set to ` true ` ,
613632multicast packets will also be received on the local interface.
614633
634+ This method throws ` EBADF ` if called on an unbound socket.
635+
615636### ` socket.setMulticastTTL(ttl) `
616637<!-- YAML
617638added: v0.3.8
@@ -627,6 +648,8 @@ decremented to 0 by a router, it will not be forwarded.
627648
628649The ` ttl ` argument may be between 0 and 255. The default on most systems is ` 1 ` .
629650
651+ This method throws ` EBADF ` if called on an unbound socket.
652+
630653### ` socket.setRecvBufferSize(size) `
631654<!-- YAML
632655added: v8.7.0
@@ -637,6 +660,8 @@ added: v8.7.0
637660Sets the ` SO_RCVBUF ` socket option. Sets the maximum socket receive buffer
638661in bytes.
639662
663+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
664+
640665### ` socket.setSendBufferSize(size) `
641666<!-- YAML
642667added: v8.7.0
@@ -647,6 +672,8 @@ added: v8.7.0
647672Sets the ` SO_SNDBUF ` socket option. Sets the maximum socket send buffer
648673in bytes.
649674
675+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
676+
650677### ` socket.setTTL(ttl) `
651678<!-- YAML
652679added: v0.1.101
@@ -663,6 +690,8 @@ Changing TTL values is typically done for network probes or when multicasting.
663690The ` ttl ` argument may be between between 1 and 255. The default on most systems
664691is 64.
665692
693+ This method throws ` EBADF ` if called on an unbound socket.
694+
666695### ` socket.unref() `
667696<!-- YAML
668697added: v0.9.1
@@ -741,6 +770,8 @@ and `udp6` sockets). The bound address and port can be retrieved using
741770[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
742771
743772[ `'close'` ] : #dgram_event_close
773+ [ `ERR_SOCKET_BAD_PORT` ] : errors.html#errors_err_socket_bad_port
774+ [ `ERR_SOCKET_BUFFER_SIZE` ] : errors.html#errors_err_socket_buffer_size
744775[ `ERR_SOCKET_DGRAM_IS_CONNECTED` ] : errors.html#errors_err_socket_dgram_is_connected
745776[ `ERR_SOCKET_DGRAM_NOT_CONNECTED` ] : errors.html#errors_err_socket_dgram_not_connected
746777[ `Error` ] : errors.html#errors_class_error
0 commit comments