@@ -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:
@@ -143,6 +146,9 @@ is not specified, the operating system will choose one interface and will add
143
146
membership to it. To add membership to every available interface, call
144
147
` socket.addSourceSpecificMembership() ` multiple times, once per interface.
145
148
149
+ When called on an unbound socket, this method will implicitly bind to a random
150
+ port, listening on all interfaces.
151
+
146
152
### ` socket.address() `
147
153
<!-- YAML
148
154
added: v0.1.99
@@ -154,6 +160,8 @@ Returns an object containing the address information for a socket.
154
160
For UDP sockets, this object will contain ` address ` , ` family ` and ` port `
155
161
properties.
156
162
163
+ This method throws ` EBADF ` if called on an unbound socket.
164
+
157
165
### ` socket.bind([port][, address][, callback]) `
158
166
<!-- YAML
159
167
added: v0.1.99
@@ -298,8 +306,9 @@ added: v12.0.0
298
306
-->
299
307
300
308
A synchronous function that disassociates a connected ` dgram.Socket ` from
301
- its remote address. Trying to call ` disconnect() ` on an already disconnected
302
- socket will result in an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception.
309
+ its remote address. Trying to call ` disconnect() ` on an unbound or already
310
+ disconnected socket will result in an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ]
311
+ exception.
303
312
304
313
### ` socket.dropMembership(multicastAddress[, multicastInterface]) `
305
314
<!-- YAML
@@ -344,13 +353,17 @@ added: v8.7.0
344
353
345
354
* Returns: {number} the ` SO_RCVBUF ` socket receive buffer size in bytes.
346
355
356
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
357
+
347
358
### ` socket.getSendBufferSize() `
348
359
<!-- YAML
349
360
added: v8.7.0
350
361
-->
351
362
352
363
* Returns: {number} the ` SO_SNDBUF ` socket send buffer size in bytes.
353
364
365
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
366
+
354
367
### ` socket.ref() `
355
368
<!-- YAML
356
369
added: v0.9.1
@@ -377,8 +390,8 @@ added: v12.0.0
377
390
* Returns: {Object}
378
391
379
392
Returns an object containing the ` address ` , ` family ` , and ` port ` of the remote
380
- endpoint. It throws an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception if the
381
- socket is not connected.
393
+ endpoint. This method throws an [ ` ERR_SOCKET_DGRAM_NOT_CONNECTED ` ] [ ] exception
394
+ if the socket is not connected.
382
395
383
396
### ` socket.send(msg[, offset, length][, port][, address][, callback]) `
384
397
<!-- YAML
@@ -452,6 +465,8 @@ Offset and length are optional but both *must* be set if either are used.
452
465
They are supported only when the first argument is a ` Buffer ` , a ` TypedArray ` ,
453
466
or a ` DataView ` .
454
467
468
+ This method throws [ ` ERR_SOCKET_BAD_PORT ` ] [ ] if called on an unbound socket.
469
+
455
470
Example of sending a UDP packet to a port on ` localhost ` ;
456
471
457
472
``` js
@@ -532,6 +547,8 @@ added: v0.6.9
532
547
Sets or clears the ` SO_BROADCAST ` socket option. When set to ` true ` , UDP
533
548
packets may be sent to a local interface's broadcast address.
534
549
550
+ This method throws ` EBADF ` if called on an unbound socket.
551
+
535
552
### ` socket.setMulticastInterface(multicastInterface) `
536
553
<!-- YAML
537
554
added: v8.6.0
@@ -558,6 +575,8 @@ also use explicit scope in addresses, so only packets sent to a multicast
558
575
address without specifying an explicit scope are affected by the most recent
559
576
successful use of this call.
560
577
578
+ This method throws ` EBADF ` if called on an unbound socket.
579
+
561
580
#### Example: IPv6 outgoing multicast interface
562
581
563
582
On most systems, where scope format uses the interface name:
@@ -620,6 +639,8 @@ added: v0.3.8
620
639
Sets or clears the ` IP_MULTICAST_LOOP ` socket option. When set to ` true ` ,
621
640
multicast packets will also be received on the local interface.
622
641
642
+ This method throws ` EBADF ` if called on an unbound socket.
643
+
623
644
### ` socket.setMulticastTTL(ttl) `
624
645
<!-- YAML
625
646
added: v0.3.8
@@ -635,6 +656,8 @@ decremented to 0 by a router, it will not be forwarded.
635
656
636
657
The ` ttl ` argument may be between 0 and 255. The default on most systems is ` 1 ` .
637
658
659
+ This method throws ` EBADF ` if called on an unbound socket.
660
+
638
661
### ` socket.setRecvBufferSize(size) `
639
662
<!-- YAML
640
663
added: v8.7.0
@@ -645,6 +668,8 @@ added: v8.7.0
645
668
Sets the ` SO_RCVBUF ` socket option. Sets the maximum socket receive buffer
646
669
in bytes.
647
670
671
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
672
+
648
673
### ` socket.setSendBufferSize(size) `
649
674
<!-- YAML
650
675
added: v8.7.0
@@ -655,6 +680,8 @@ added: v8.7.0
655
680
Sets the ` SO_SNDBUF ` socket option. Sets the maximum socket send buffer
656
681
in bytes.
657
682
683
+ This method throws [ ` ERR_SOCKET_BUFFER_SIZE ` ] [ ] if called on an unbound socket.
684
+
658
685
### ` socket.setTTL(ttl) `
659
686
<!-- YAML
660
687
added: v0.1.101
@@ -671,6 +698,8 @@ Changing TTL values is typically done for network probes or when multicasting.
671
698
The ` ttl ` argument may be between between 1 and 255. The default on most systems
672
699
is 64.
673
700
701
+ This method throws ` EBADF ` if called on an unbound socket.
702
+
674
703
### ` socket.unref() `
675
704
<!-- YAML
676
705
added: v0.9.1
@@ -749,6 +778,8 @@ and `udp6` sockets). The bound address and port can be retrieved using
749
778
[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
750
779
751
780
[ `'close'` ] : #dgram_event_close
781
+ [ `ERR_SOCKET_BAD_PORT` ] : errors.html#errors_err_socket_bad_port
782
+ [ `ERR_SOCKET_BUFFER_SIZE` ] : errors.html#errors_err_socket_buffer_size
752
783
[ `ERR_SOCKET_DGRAM_IS_CONNECTED` ] : errors.html#errors_err_socket_dgram_is_connected
753
784
[ `ERR_SOCKET_DGRAM_NOT_CONNECTED` ] : errors.html#errors_err_socket_dgram_not_connected
754
785
[ `Error` ] : errors.html#errors_class_error
0 commit comments