diff --git a/doc/api/dgram.md b/doc/api/dgram.md index 91d6f74933..538e104c93 100644 --- a/doc/api/dgram.md +++ b/doc/api/dgram.md @@ -29,6 +29,9 @@ server.bind(41234); ``` ## Class: dgram.Socket + The `dgram.Socket` object is an [`EventEmitter`][] that encapsulates the datagram functionality. @@ -37,11 +40,17 @@ New instances of `dgram.Socket` are created using [`dgram.createSocket()`][]. The `new` keyword is not to be used to create `dgram.Socket` instances. ### Event: 'close' + The `'close'` event is emitted after a socket is closed with [`close()`][]. Once triggered, no new `'message'` events will be emitted on this socket. ### Event: 'error' + * `exception` {Error} @@ -49,11 +58,17 @@ The `'error'` event is emitted whenever any error occurs. The event handler function is passed a single Error object. ### Event: 'listening' + The `'listening'` event is emitted whenever a socket begins listening for datagram messages. This occurs as soon as UDP sockets are created. ### Event: 'message' + * `msg` {Buffer} - The message * `rinfo` {Object} - Remote address information @@ -85,12 +100,18 @@ one interface and will add membership to it. To add membership to every available interface, call `addMembership` multiple times, once per interface. ### socket.address() + Returns an object containing the address information for a socket. For UDP sockets, this object will contain `address`, `family` and `port` properties. ### socket.bind([port][, address][, callback]) + * `port` {Number} - Integer, Optional * `address` {String}, Optional @@ -139,6 +160,9 @@ server.bind(41234); ``` ### socket.bind(options[, callback]) + * `options` {Object} - Required. Supports the following properties: * `port` {Number} - Required. @@ -172,6 +196,9 @@ socket.bind({ ``` ### socket.close([callback]) + Close the underlying socket and stop listening for data on it. If a callback is provided, it is added as a listener for the [`'close'`][] event. @@ -193,6 +220,9 @@ If `multicastInterface` is not specified, the operating system will attempt to drop membership on all valid interfaces. ### socket.send(msg, [offset, length,] port, address[, callback]) + * `msg` {Buffer|String|Array} Message to be sent * `offset` {Number} Integer. Optional. Offset in the buffer where the message starts. @@ -300,6 +330,9 @@ Sets or clears the `SO_BROADCAST` socket option. When set to `true`, UDP packets may be sent to a local interface's broadcast address. ### socket.setMulticastLoopback(flag) + * `flag` {Boolean} @@ -307,6 +340,9 @@ Sets or clears the `IP_MULTICAST_LOOP` socket option. When set to `true`, multicast packets will also be received on the local interface. ### socket.setMulticastTTL(ttl) + * `ttl` {Number} Integer @@ -320,6 +356,9 @@ The argument passed to to `socket.setMulticastTTL()` is a number of hops between 0 and 255. The default on most systems is `1` but can vary. ### socket.setTTL(ttl) + * `ttl` {Number} Integer @@ -333,6 +372,9 @@ The argument to `socket.setTTL()` is a number of hops between 1 and 255. The default on most systems is 64 but can vary. ### socket.ref() + By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The `socket.unref()` method can be used @@ -346,6 +388,9 @@ The `socket.ref()` method returns a reference to the socket so calls can be chained. ### socket.unref() + By default, binding a socket will cause it to block the Node.js process from exiting as long as the socket is open. The `socket.unref()` method can be used @@ -383,6 +428,9 @@ s.bind(1234, () => { ## `dgram` module functions ### dgram.createSocket(options[, callback]) + * `options` {Object} * `callback` {Function} Attached as a listener to `'message'` events. @@ -405,6 +453,9 @@ and `udp6` sockets). The bound address and port can be retrieved using [`socket.address().address`][] and [`socket.address().port`][]. ### dgram.createSocket(type[, callback]) + * `type` {String} - Either 'udp4' or 'udp6' * `callback` {Function} - Attached as a listener to `'message'` events.