@@ -137,6 +137,11 @@ properties.
137137### socket.bind([ port] [ , address ] [ , callback] )
138138<!-- YAML
139139added: 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.
140145-->
141146
142147* ` port ` {integer}
@@ -216,7 +221,7 @@ Specifying both a `'listening'` event listener and passing a
216221useful.
217222
218223The ` 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
220225` exclusive ` is set to ` false ` (the default), cluster workers will use the same
221226underlying socket handle allowing connection handling duties to be shared.
222227When ` exclusive ` is ` true ` , however, the handle is not shared and attempted
@@ -311,6 +316,8 @@ added: v8.7.0
311316added: v0.9.1
312317-->
313318
319+ * Returns: {dgram.Socket}
320+
314321By default, binding a socket will cause it to block the Node.js process from
315322exiting as long as the socket is open. The ` socket.unref() ` method can be used
316323to exclude the socket from the reference counting that keeps the Node.js
@@ -444,7 +451,7 @@ client.connect(41234, 'localhost', (err) => {
444451});
445452```
446453
447- ** A Note about UDP datagram size**
454+ #### Note about UDP datagram size
448455
449456The maximum size of an ` IPv4/v6 ` datagram depends on the ` MTU `
450457(_ Maximum Transmission Unit_ ) and on the ` Payload Length ` field size.
@@ -626,6 +633,8 @@ The default on most systems is 64 but can vary.
626633added: v0.9.1
627634-->
628635
636+ * Returns: {dgram.Socket}
637+
629638By default, binding a socket will cause it to block the Node.js process from
630639exiting as long as the socket is open. The ` socket.unref() ` method can be used
631640to 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.
637646The ` socket.unref() ` method returns a reference to the socket so calls can be
638647chained.
639648
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-
661649## ` dgram ` module functions
662650
663651### dgram.createSocket(options[ , callback] )
@@ -708,9 +696,7 @@ added: v0.1.99
708696* ` callback ` {Function} - Attached as a listener to ` 'message' ` events.
709697* Returns: {dgram.Socket}
710698
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 ` .
714700
715701Once the socket is created, calling [ ` socket.bind() ` ] [ ] will instruct the
716702socket 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
720706[ ` socket.address().address ` ] [ ] and [ ` socket.address().port ` ] [ ] .
721707
722708[ `'close'` ] : #dgram_event_close
723- [ `Error` ] : errors.html#errors_class_error
724709[ `ERR_SOCKET_DGRAM_IS_CONNECTED` ] : errors.html#errors_err_socket_dgram_is_connected
725710[ `ERR_SOCKET_DGRAM_NOT_CONNECTED` ] : errors.html#errors_err_socket_dgram_not_connected
711+ [ `Error` ] : errors.html#errors_class_error
726712[ `System Error` ] : errors.html#errors_class_systemerror
727713[ `close()` ] : #dgram_socket_close_callback
728714[ `cluster` ] : cluster.html
729715[ `connect()` ] : #dgram_socket_connect_port_address_callback
730- [ `dgram.Socket#bind()` ] : #dgram_socket_bind_options_callback
731716[ `dgram.createSocket()` ] : #dgram_dgram_createsocket_options_callback
732717[ `dns.lookup()` ] : dns.html#dns_dns_lookup_hostname_options_callback
733718[ `socket.address().address` ] : #dgram_socket_address
0 commit comments