@@ -108,6 +108,9 @@ Tells the kernel to join a multicast group at the given `multicastAddress` and
108
108
one interface and will add membership to it. To add membership to every
109
109
available interface, call ` addMembership ` multiple times, once per interface.
110
110
111
+ When called on an unbound socket, this method will implicitly bind to a random
112
+ port, listening on all interfaces.
113
+
111
114
When sharing a UDP socket across multiple ` cluster ` workers, the
112
115
` socket.addMembership() ` function must be called only once or an
113
116
` EADDRINUSE ` error will occur:
@@ -141,6 +144,9 @@ is not specified, the operating system will choose one interface and will add
141
144
membership to it. To add membership to every available interface, call
142
145
` socket.addSourceSpecificMembership() ` multiple times, once per interface.
143
146
147
+ When called on an unbound socket, this method will implicitly bind to a random
148
+ port, listening on all interfaces.
149
+
144
150
### ` socket.address() `
145
151
<!-- YAML
146
152
added: v0.1.99
@@ -152,6 +158,8 @@ Returns an object containing the address information for a socket.
152
158
For UDP sockets, this object will contain ` address ` , ` family ` and ` port `
153
159
properties.
154
160
161
+ This method throws ` EBADF ` if called on an unbound socket.
162
+
155
163
### ` socket.bind([port][, address][, callback]) `
156
164
<!-- YAML
157
165
added: v0.1.99
@@ -296,8 +304,9 @@ added: v12.0.0
296
304
-->
297
305
298
306
A 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.
301
310
302
311
### ` socket.dropMembership(multicastAddress[, multicastInterface]) `
303
312
<!-- YAML
@@ -340,13 +349,17 @@ added: v8.7.0
340
349
341
350
* Returns: {number} the ` SO_RCVBUF ` socket receive buffer size in bytes.
342
351
352
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
353
+
343
354
### ` socket.getSendBufferSize() `
344
355
<!-- YAML
345
356
added: v8.7.0
346
357
-->
347
358
348
359
* Returns: {number} the ` SO_SNDBUF ` socket send buffer size in bytes.
349
360
361
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
362
+
350
363
### ` socket.ref() `
351
364
<!-- YAML
352
365
added: v0.9.1
@@ -373,8 +386,8 @@ added: v12.0.0
373
386
* Returns: {Object}
374
387
375
388
Returns 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.
378
391
379
392
### ` socket.send(msg[, offset, length][, port][, address][, callback]) `
380
393
<!-- YAML
@@ -444,6 +457,8 @@ the error is emitted as an `'error'` event on the `socket` object.
444
457
Offset and length are optional but both * must* be set if either are used.
445
458
They are supported only when the first argument is a ` Buffer ` or ` Uint8Array ` .
446
459
460
+ This method throws [ ` ERR_SOCKET_BAD_PORT ` ] [ ] if called on an unbound socket.
461
+
447
462
Example of sending a UDP packet to a port on ` localhost ` ;
448
463
449
464
``` js
@@ -524,6 +539,8 @@ added: v0.6.9
524
539
Sets or clears the ` SO_BROADCAST ` socket option. When set to ` true ` , UDP
525
540
packets may be sent to a local interface's broadcast address.
526
541
542
+ This method throws ` EBADF ` if called on an unbound socket.
543
+
527
544
### ` socket.setMulticastInterface(multicastInterface) `
528
545
<!-- YAML
529
546
added: v8.6.0
@@ -550,6 +567,8 @@ also use explicit scope in addresses, so only packets sent to a multicast
550
567
address without specifying an explicit scope are affected by the most recent
551
568
successful use of this call.
552
569
570
+ This method throws ` EBADF ` if called on an unbound socket.
571
+
553
572
#### Example: IPv6 outgoing multicast interface
554
573
555
574
On most systems, where scope format uses the interface name:
@@ -612,6 +631,8 @@ added: v0.3.8
612
631
Sets or clears the ` IP_MULTICAST_LOOP ` socket option. When set to ` true ` ,
613
632
multicast packets will also be received on the local interface.
614
633
634
+ This method throws ` EBADF ` if called on an unbound socket.
635
+
615
636
### ` socket.setMulticastTTL(ttl) `
616
637
<!-- YAML
617
638
added: v0.3.8
@@ -627,6 +648,8 @@ decremented to 0 by a router, it will not be forwarded.
627
648
628
649
The ` ttl ` argument may be between 0 and 255. The default on most systems is ` 1 ` .
629
650
651
+ This method throws ` EBADF ` if called on an unbound socket.
652
+
630
653
### ` socket.setRecvBufferSize(size) `
631
654
<!-- YAML
632
655
added: v8.7.0
@@ -637,6 +660,8 @@ added: v8.7.0
637
660
Sets the ` SO_RCVBUF ` socket option. Sets the maximum socket receive buffer
638
661
in bytes.
639
662
663
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
664
+
640
665
### ` socket.setSendBufferSize(size) `
641
666
<!-- YAML
642
667
added: v8.7.0
@@ -647,6 +672,8 @@ added: v8.7.0
647
672
Sets the ` SO_SNDBUF ` socket option. Sets the maximum socket send buffer
648
673
in bytes.
649
674
675
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
676
+
650
677
### ` socket.setTTL(ttl) `
651
678
<!-- YAML
652
679
added: v0.1.101
@@ -663,6 +690,8 @@ Changing TTL values is typically done for network probes or when multicasting.
663
690
The ` ttl ` argument may be between between 1 and 255. The default on most systems
664
691
is 64.
665
692
693
+ This method throws ` EBADF ` if called on an unbound socket.
694
+
666
695
### ` socket.unref() `
667
696
<!-- YAML
668
697
added: v0.9.1
@@ -741,6 +770,8 @@ and `udp6` sockets). The bound address and port can be retrieved using
741
770
[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
742
771
743
772
[ `'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
744
775
[ `ERR_SOCKET_DGRAM_IS_CONNECTED` ] : errors.html#errors_err_socket_dgram_is_connected
745
776
[ `ERR_SOCKET_DGRAM_NOT_CONNECTED` ] : errors.html#errors_err_socket_dgram_not_connected
746
777
[ `Error` ] : errors.html#errors_class_error
0 commit comments