@@ -137,6 +137,11 @@ properties.
137
137
### socket.bind([ port] [ , address ] [ , callback] )
138
138
<!-- YAML
139
139
added: v0.1.99
140
+ changes:
141
+ - version: v0.10
142
+ description: The method was changed to an asynchronous execution model.
143
+ Legacy code would need to be changed to pass a callback
144
+ function to the method call.
140
145
-->
141
146
142
147
* ` port ` {integer}
@@ -216,7 +221,7 @@ Specifying both a `'listening'` event listener and passing a
216
221
useful.
217
222
218
223
The ` options ` object may contain an additional ` exclusive ` property that is
219
- used when using ` dgram.Socket ` objects with the [ ` cluster ` ] module. When
224
+ used when using ` dgram.Socket ` objects with the [ ` cluster ` ] [ ] module. When
220
225
` exclusive ` is set to ` false ` (the default), cluster workers will use the same
221
226
underlying socket handle allowing connection handling duties to be shared.
222
227
When ` exclusive ` is ` true ` , however, the handle is not shared and attempted
@@ -311,6 +316,8 @@ added: v8.7.0
311
316
added: v0.9.1
312
317
-->
313
318
319
+ * Returns: {dgram.Socket}
320
+
314
321
By default, binding a socket will cause it to block the Node.js process from
315
322
exiting as long as the socket is open. The ` socket.unref() ` method can be used
316
323
to exclude the socket from the reference counting that keeps the Node.js
@@ -444,7 +451,7 @@ client.connect(41234, 'localhost', (err) => {
444
451
});
445
452
```
446
453
447
- ** A Note about UDP datagram size**
454
+ #### Note about UDP datagram size
448
455
449
456
The maximum size of an ` IPv4/v6 ` datagram depends on the ` MTU `
450
457
(_ Maximum Transmission Unit_ ) and on the ` Payload Length ` field size.
@@ -626,6 +633,8 @@ The default on most systems is 64 but can vary.
626
633
added: v0.9.1
627
634
-->
628
635
636
+ * Returns: {dgram.Socket}
637
+
629
638
By default, binding a socket will cause it to block the Node.js process from
630
639
exiting as long as the socket is open. The ` socket.unref() ` method can be used
631
640
to exclude the socket from the reference counting that keeps the Node.js
@@ -637,27 +646,6 @@ Calling `socket.unref()` multiple times will have no addition effect.
637
646
The ` socket.unref() ` method returns a reference to the socket so calls can be
638
647
chained.
639
648
640
- ### Change to asynchronous ` socket.bind() ` behavior
641
-
642
- As of Node.js v0.10, [ ` dgram.Socket#bind() ` ] [ ] changed to an asynchronous
643
- execution model. Legacy code would use synchronous behavior:
644
-
645
- ``` js
646
- const s = dgram .createSocket (' udp4' );
647
- s .bind (1234 );
648
- s .addMembership (' 224.0.0.114' );
649
- ```
650
-
651
- Such legacy code would need to be changed to pass a callback function to the
652
- [ ` dgram.Socket#bind() ` ] [ ] function:
653
-
654
- ``` js
655
- const s = dgram .createSocket (' udp4' );
656
- s .bind (1234 , () => {
657
- s .addMembership (' 224.0.0.114' );
658
- });
659
- ```
660
-
661
649
## ` dgram ` module functions
662
650
663
651
### dgram.createSocket(options[ , callback] )
@@ -708,9 +696,7 @@ added: v0.1.99
708
696
* ` callback ` {Function} - Attached as a listener to ` 'message' ` events.
709
697
* Returns: {dgram.Socket}
710
698
711
- Creates a ` dgram.Socket ` object of the specified ` type ` . The ` type ` argument
712
- can be either ` 'udp4' ` or ` 'udp6' ` . An optional ` callback ` function can be
713
- passed which is added as a listener for ` 'message' ` events.
699
+ Creates a ` dgram.Socket ` object of the specified ` type ` .
714
700
715
701
Once the socket is created, calling [ ` socket.bind() ` ] [ ] will instruct the
716
702
socket to begin listening for datagram messages. When ` address ` and ` port ` are
@@ -720,14 +706,13 @@ and `udp6` sockets). The bound address and port can be retrieved using
720
706
[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
721
707
722
708
[ `'close'` ] : #dgram_event_close
723
- [ `Error` ] : errors.html#errors_class_error
724
709
[ `ERR_SOCKET_DGRAM_IS_CONNECTED` ] : errors.html#errors_err_socket_dgram_is_connected
725
710
[ `ERR_SOCKET_DGRAM_NOT_CONNECTED` ] : errors.html#errors_err_socket_dgram_not_connected
711
+ [ `Error` ] : errors.html#errors_class_error
726
712
[ `System Error` ] : errors.html#errors_class_systemerror
727
713
[ `close()` ] : #dgram_socket_close_callback
728
714
[ `cluster` ] : cluster.html
729
715
[ `connect()` ] : #dgram_socket_connect_port_address_callback
730
- [ `dgram.Socket#bind()` ] : #dgram_socket_bind_options_callback
731
716
[ `dgram.createSocket()` ] : #dgram_dgram_createsocket_options_callback
732
717
[ `dns.lookup()` ] : dns.html#dns_dns_lookup_hostname_options_callback
733
718
[ `socket.address().address` ] : #dgram_socket_address
0 commit comments