@@ -112,12 +112,13 @@ added: v0.1.99
112112* ` callback ` {Function} with no parameters, Optional. Called when
113113 binding is complete.
114114
115- For UDP sockets, causes the ` dgram.Socket ` to listen for datagram messages on a
116- named ` port ` and optional ` address ` . If ` port ` is not specified, the operating
117- system will attempt to bind to a random port. If ` address ` is not specified,
118- the operating system will attempt to listen on all addresses. Once binding is
119- complete, a ` 'listening' ` event is emitted and the optional ` callback ` function
120- is called.
115+ For UDP sockets, causes the ` dgram.Socket ` to listen for datagram
116+ messages on a named ` port ` and optional ` address ` . If ` port ` is not
117+ specified or is ` 0 ` , the operating system will attempt to bind to a
118+ random port. If ` address ` is not specified, the operating system will
119+ attempt to listen on all addresses. Once binding is complete, a
120+ ` 'listening' ` event is emitted and the optional ` callback ` function is
121+ called.
121122
122123Note that specifying both a ` 'listening' ` event listener and passing a
123124` callback ` to the ` socket.bind() ` method is not harmful but not very
@@ -159,18 +160,23 @@ added: v0.11.14
159160-->
160161
161162* ` options ` {Object} - Required. Supports the following properties:
162- * ` port ` {Number} - Required .
163+ * ` port ` {Number} - Optional .
163164 * ` address ` {String} - Optional.
164165 * ` exclusive ` {Boolean} - Optional.
165166* ` callback ` {Function} - Optional.
166167
167- For UDP sockets, causes the ` dgram.Socket ` to listen for datagram messages on a
168- named ` port ` and optional ` address ` that are passed as properties of an
169- ` options ` object passed as the first argument. If ` port ` is not specified, the
170- operating system will attempt to bind to a random port. If ` address ` is not
171- specified, the operating system will attempt to listen on all addresses. Once
172- binding is complete, a ` 'listening' ` event is emitted and the optional
173- ` callback ` function is called.
168+ For UDP sockets, causes the ` dgram.Socket ` to listen for datagram
169+ messages on a named ` port ` and optional ` address ` that are passed as
170+ properties of an ` options ` object passed as the first argument. If
171+ ` port ` is not specified or is ` 0 ` , the operating system will attempt
172+ to bind to a random port. If ` address ` is not specified, the operating
173+ system will attempt to listen on all addresses. Once binding is
174+ complete, a ` 'listening' ` event is emitted and the optional ` callback `
175+ function is called.
176+
177+ Note that specifying both a ` 'listening' ` event listener and passing a
178+ ` callback ` to the ` socket.bind() ` method is not harmful but not very
179+ useful.
174180
175181The ` options ` object may contain an additional ` exclusive ` property that is
176182use when using ` dgram.Socket ` objects with the [ ` cluster ` ] module. When
@@ -179,6 +185,12 @@ underlying socket handle allowing connection handling duties to be shared.
179185When ` exclusive ` is ` true ` , however, the handle is not shared and attempted
180186port sharing results in an error.
181187
188+ A bound datagram socket keeps the Node.js process running to receive
189+ datagram messages.
190+
191+ If binding fails, an ` 'error' ` event is generated. In rare case (e.g.
192+ attempting to bind with a closed socket), an [ ` Error ` ] [ ] may be thrown.
193+
182194An example socket listening on an exclusive port is shown below.
183195
184196``` js
0 commit comments