Skip to content

Commit 077a2ba

Browse files
tflanaganrvagg
authored andcommitted
doc: sort dgram alphabetically
Reorders, with no contextual changes, the dgram documentation alphabetically. PR-URL: #3662 Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent cb23440 commit 077a2ba

File tree

1 file changed

+149
-152
lines changed

1 file changed

+149
-152
lines changed

doc/api/dgram.markdown

+149-152
Original file line numberDiff line numberDiff line change
@@ -20,66 +20,11 @@ You have to change it to this:
2020
s.addMembership('224.0.0.114');
2121
});
2222

23-
24-
## dgram.createSocket(type[, callback])
25-
26-
* `type` String. Either 'udp4' or 'udp6'
27-
* `callback` Function. Attached as a listener to `message` events.
28-
Optional
29-
* Returns: Socket object
30-
31-
Creates a datagram Socket of the specified types. Valid types are `udp4`
32-
and `udp6`.
33-
34-
Takes an optional callback which is added as a listener for `message` events.
35-
36-
Call `socket.bind()` if you want to receive datagrams. `socket.bind()` will
37-
bind to the "all interfaces" address on a random port (it does the right thing
38-
for both `udp4` and `udp6` sockets). You can then retrieve the address and port
39-
with `socket.address().address` and `socket.address().port`.
40-
41-
## dgram.createSocket(options[, callback])
42-
* `options` Object
43-
* `callback` Function. Attached as a listener to `message` events.
44-
* Returns: Socket object
45-
46-
The `options` object should contain a `type` field of either `udp4` or `udp6`
47-
and an optional boolean `reuseAddr` field.
48-
49-
When `reuseAddr` is `true` `socket.bind()` will reuse the address, even if
50-
another process has already bound a socket on it. `reuseAddr` defaults to
51-
`false`.
52-
53-
Takes an optional callback which is added as a listener for `message` events.
54-
55-
Call `socket.bind()` if you want to receive datagrams. `socket.bind()` will
56-
bind to the "all interfaces" address on a random port (it does the right thing
57-
for both `udp4` and `udp6` sockets). You can then retrieve the address and port
58-
with `socket.address().address` and `socket.address().port`.
59-
6023
## Class: dgram.Socket
6124

6225
The dgram Socket class encapsulates the datagram functionality. It
6326
should be created via `dgram.createSocket(...)`
6427

65-
### Event: 'message'
66-
67-
* `msg` Buffer object. The message
68-
* `rinfo` Object. Remote address information
69-
70-
Emitted when a new datagram is available on a socket. `msg` is a `Buffer` and
71-
`rinfo` is an object with the sender's address information:
72-
73-
socket.on('message', function(msg, rinfo) {
74-
console.log('Received %d bytes from %s:%d\n',
75-
msg.length, rinfo.address, rinfo.port);
76-
});
77-
78-
### Event: 'listening'
79-
80-
Emitted when a socket starts listening for datagrams. This happens as soon as UDP sockets
81-
are created.
82-
8328
### Event: 'close'
8429

8530
Emitted after a socket is closed with `close()`. No new `message` events will be emitted
@@ -91,72 +36,38 @@ on this socket.
9136

9237
Emitted when an error occurs.
9338

94-
### socket.send(buf, offset, length, port, address[, callback])
95-
96-
* `buf` Buffer object or string. Message to be sent
97-
* `offset` Integer. Offset in the buffer where the message starts.
98-
* `length` Integer. Number of bytes in the message.
99-
* `port` Integer. Destination port.
100-
* `address` String. Destination hostname or IP address.
101-
* `callback` Function. Called when the message has been sent. Optional.
102-
103-
For UDP sockets, the destination port and address must be specified. A string
104-
may be supplied for the `address` parameter, and it will be resolved with DNS.
105-
106-
If the address is omitted or is an empty string, `'0.0.0.0'` or `'::0'` is used
107-
instead. Depending on the network configuration, those defaults may or may not
108-
work; it's best to be explicit about the destination address.
39+
### Event: 'listening'
10940

110-
If the socket has not been previously bound with a call to `bind`, it gets
111-
assigned a random port number and is bound to the "all interfaces" address
112-
(`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
41+
Emitted when a socket starts listening for datagrams. This happens as soon as UDP sockets
42+
are created.
11343

114-
An optional callback may be specified to detect DNS errors or for determining
115-
when it's safe to reuse the `buf` object. Note that DNS lookups delay the time
116-
to send for at least one tick. The only way to know for sure that the datagram
117-
has been sent is by using a callback. If an error occurs and a callback is
118-
given, the error will be the first argument to the callback. If a callback is
119-
not given, the error is emitted as an `'error'` event on the `socket` object.
44+
### Event: 'message'
12045

121-
With consideration for multi-byte characters, `offset` and `length` will
122-
be calculated with respect to
123-
[byte length](buffer.html#buffer_class_method_buffer_bytelength_string_encoding)
124-
and not the character position.
46+
* `msg` Buffer object. The message
47+
* `rinfo` Object. Remote address information
12548

126-
Example of sending a UDP packet to a random port on `localhost`;
49+
Emitted when a new datagram is available on a socket. `msg` is a `Buffer` and
50+
`rinfo` is an object with the sender's address information:
12751

128-
var dgram = require('dgram');
129-
var message = new Buffer("Some bytes");
130-
var client = dgram.createSocket("udp4");
131-
client.send(message, 0, message.length, 41234, "localhost", function(err) {
132-
client.close();
52+
socket.on('message', function(msg, rinfo) {
53+
console.log('Received %d bytes from %s:%d\n',
54+
msg.length, rinfo.address, rinfo.port);
13355
});
13456

135-
**A Note about UDP datagram size**
57+
### socket.addMembership(multicastAddress[, multicastInterface])
13658

137-
The maximum size of an `IPv4/v6` datagram depends on the `MTU` (_Maximum Transmission Unit_)
138-
and on the `Payload Length` field size.
59+
* `multicastAddress` String
60+
* `multicastInterface` String, Optional
13961

140-
- The `Payload Length` field is `16 bits` wide, which means that a normal payload
141-
cannot be larger than 64K octets including internet header and data
142-
(65,507 bytes = 65,535 − 8 bytes UDP header − 20 bytes IP header);
143-
this is generally true for loopback interfaces, but such long datagrams
144-
are impractical for most hosts and networks.
62+
Tells the kernel to join a multicast group with `IP_ADD_MEMBERSHIP` socket option.
14563

146-
- The `MTU` is the largest size a given link layer technology can support for datagrams.
147-
For any link, `IPv4` mandates a minimum `MTU` of `68` octets, while the recommended `MTU`
148-
for IPv4 is `576` (typically recommended as the `MTU` for dial-up type applications),
149-
whether they arrive whole or in fragments.
64+
If `multicastInterface` is not specified, the OS will try to add membership to all valid
65+
interfaces.
15066

151-
For `IPv6`, the minimum `MTU` is `1280` octets, however, the mandatory minimum
152-
fragment reassembly buffer size is `1500` octets.
153-
The value of `68` octets is very small, since most current link layer technologies have
154-
a minimum `MTU` of `1500` (like Ethernet).
67+
### socket.address()
15568

156-
Note that it's impossible to know in advance the MTU of each link through which
157-
a packet might travel, and that generally sending a datagram greater than
158-
the (receiver) `MTU` won't work (the packet gets silently dropped, without
159-
informing the source that the data did not reach its intended recipient).
69+
Returns an object containing the address information for a socket. For UDP sockets,
70+
this object will contain `address` , `family` and `port`.
16071

16172
### socket.bind([port][, address][, callback])
16273

@@ -204,7 +115,6 @@ Example of a UDP server listening on port 41234:
204115
server.bind(41234);
205116
// server listening 0.0.0.0:41234
206117

207-
208118
### socket.bind(options[, callback])
209119

210120
* `options` {Object} - Required. Supports the following properties:
@@ -230,16 +140,90 @@ shown below.
230140
exclusive: true
231141
});
232142

233-
234143
### socket.close([callback])
235144

236145
Close the underlying socket and stop listening for data on it. If a callback is
237146
provided, it is added as a listener for the ['close'](#dgram_event_close) event.
238147

239-
### socket.address()
148+
### socket.dropMembership(multicastAddress[, multicastInterface])
240149

241-
Returns an object containing the address information for a socket. For UDP sockets,
242-
this object will contain `address` , `family` and `port`.
150+
* `multicastAddress` String
151+
* `multicastInterface` String, Optional
152+
153+
Opposite of `addMembership` - tells the kernel to leave a multicast group with
154+
`IP_DROP_MEMBERSHIP` socket option. This is automatically called by the kernel
155+
when the socket is closed or process terminates, so most apps will never need to call
156+
this.
157+
158+
If `multicastInterface` is not specified, the OS will try to drop membership to all valid
159+
interfaces.
160+
161+
### socket.send(buf, offset, length, port, address[, callback])
162+
163+
* `buf` Buffer object or string. Message to be sent
164+
* `offset` Integer. Offset in the buffer where the message starts.
165+
* `length` Integer. Number of bytes in the message.
166+
* `port` Integer. Destination port.
167+
* `address` String. Destination hostname or IP address.
168+
* `callback` Function. Called when the message has been sent. Optional.
169+
170+
For UDP sockets, the destination port and address must be specified. A string
171+
may be supplied for the `address` parameter, and it will be resolved with DNS.
172+
173+
If the address is omitted or is an empty string, `'0.0.0.0'` or `'::0'` is used
174+
instead. Depending on the network configuration, those defaults may or may not
175+
work; it's best to be explicit about the destination address.
176+
177+
If the socket has not been previously bound with a call to `bind`, it gets
178+
assigned a random port number and is bound to the "all interfaces" address
179+
(`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
180+
181+
An optional callback may be specified to detect DNS errors or for determining
182+
when it's safe to reuse the `buf` object. Note that DNS lookups delay the time
183+
to send for at least one tick. The only way to know for sure that the datagram
184+
has been sent is by using a callback. If an error occurs and a callback is
185+
given, the error will be the first argument to the callback. If a callback is
186+
not given, the error is emitted as an `'error'` event on the `socket` object.
187+
188+
With consideration for multi-byte characters, `offset` and `length` will
189+
be calculated with respect to
190+
[byte length](buffer.html#buffer_class_method_buffer_bytelength_string_encoding)
191+
and not the character position.
192+
193+
Example of sending a UDP packet to a random port on `localhost`;
194+
195+
var dgram = require('dgram');
196+
var message = new Buffer("Some bytes");
197+
var client = dgram.createSocket("udp4");
198+
client.send(message, 0, message.length, 41234, "localhost", function(err) {
199+
client.close();
200+
});
201+
202+
**A Note about UDP datagram size**
203+
204+
The maximum size of an `IPv4/v6` datagram depends on the `MTU` (_Maximum Transmission Unit_)
205+
and on the `Payload Length` field size.
206+
207+
- The `Payload Length` field is `16 bits` wide, which means that a normal payload
208+
cannot be larger than 64K octets including internet header and data
209+
(65,507 bytes = 65,535 − 8 bytes UDP header − 20 bytes IP header);
210+
this is generally true for loopback interfaces, but such long datagrams
211+
are impractical for most hosts and networks.
212+
213+
- The `MTU` is the largest size a given link layer technology can support for datagrams.
214+
For any link, `IPv4` mandates a minimum `MTU` of `68` octets, while the recommended `MTU`
215+
for IPv4 is `576` (typically recommended as the `MTU` for dial-up type applications),
216+
whether they arrive whole or in fragments.
217+
218+
For `IPv6`, the minimum `MTU` is `1280` octets, however, the mandatory minimum
219+
fragment reassembly buffer size is `1500` octets.
220+
The value of `68` octets is very small, since most current link layer technologies have
221+
a minimum `MTU` of `1500` (like Ethernet).
222+
223+
Note that it's impossible to know in advance the MTU of each link through which
224+
a packet might travel, and that generally sending a datagram greater than
225+
the (receiver) `MTU` won't work (the packet gets silently dropped, without
226+
informing the source that the data did not reach its intended recipient).
243227

244228
### socket.setBroadcast(flag)
245229

@@ -248,18 +232,12 @@ this object will contain `address` , `family` and `port`.
248232
Sets or clears the `SO_BROADCAST` socket option. When this option is set, UDP packets
249233
may be sent to a local interface's broadcast address.
250234

251-
### socket.setTTL(ttl)
252-
253-
* `ttl` Integer
235+
### socket.setMulticastLoopback(flag)
254236

255-
Sets the `IP_TTL` socket option. TTL stands for "Time to Live," but in this context it
256-
specifies the number of IP hops that a packet is allowed to go through. Each router or
257-
gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a
258-
router, it will not be forwarded. Changing TTL values is typically done for network
259-
probes or when multicasting.
237+
* `flag` Boolean
260238

261-
The argument to `setTTL()` is a number of hops between 1 and 255. The default on most
262-
systems is 64.
239+
Sets or clears the `IP_MULTICAST_LOOP` socket option. When this option is set, multicast
240+
packets will also be received on the local interface.
263241

264242
### socket.setMulticastTTL(ttl)
265243

@@ -273,35 +251,26 @@ decrements the TTL. If the TTL is decremented to 0 by a router, it will not be f
273251
The argument to `setMulticastTTL()` is a number of hops between 0 and 255. The default on most
274252
systems is 1.
275253

276-
### socket.setMulticastLoopback(flag)
277-
278-
* `flag` Boolean
279-
280-
Sets or clears the `IP_MULTICAST_LOOP` socket option. When this option is set, multicast
281-
packets will also be received on the local interface.
282-
283-
### socket.addMembership(multicastAddress[, multicastInterface])
284-
285-
* `multicastAddress` String
286-
* `multicastInterface` String, Optional
254+
### socket.setTTL(ttl)
287255

288-
Tells the kernel to join a multicast group with `IP_ADD_MEMBERSHIP` socket option.
256+
* `ttl` Integer
289257

290-
If `multicastInterface` is not specified, the OS will try to add membership to all valid
291-
interfaces.
258+
Sets the `IP_TTL` socket option. TTL stands for "Time to Live," but in this context it
259+
specifies the number of IP hops that a packet is allowed to go through. Each router or
260+
gateway that forwards a packet decrements the TTL. If the TTL is decremented to 0 by a
261+
router, it will not be forwarded. Changing TTL values is typically done for network
262+
probes or when multicasting.
292263

293-
### socket.dropMembership(multicastAddress[, multicastInterface])
264+
The argument to `setTTL()` is a number of hops between 1 and 255. The default on most
265+
systems is 64.
294266

295-
* `multicastAddress` String
296-
* `multicastInterface` String, Optional
267+
### socket.ref()
297268

298-
Opposite of `addMembership` - tells the kernel to leave a multicast group with
299-
`IP_DROP_MEMBERSHIP` socket option. This is automatically called by the kernel
300-
when the socket is closed or process terminates, so most apps will never need to call
301-
this.
269+
Opposite of `unref`, calling `ref` on a previously `unref`d socket will *not*
270+
let the program exit if it's the only socket left (the default behavior). If
271+
the socket is `ref`d calling `ref` again will have no effect.
302272

303-
If `multicastInterface` is not specified, the OS will try to drop membership to all valid
304-
interfaces.
273+
Returns `socket`.
305274

306275
### socket.unref()
307276

@@ -311,10 +280,38 @@ active socket in the event system. If the socket is already `unref`d calling
311280

312281
Returns `socket`.
313282

314-
### socket.ref()
283+
## dgram.createSocket(options[, callback])
284+
* `options` Object
285+
* `callback` Function. Attached as a listener to `message` events.
286+
* Returns: Socket object
315287

316-
Opposite of `unref`, calling `ref` on a previously `unref`d socket will *not*
317-
let the program exit if it's the only socket left (the default behavior). If
318-
the socket is `ref`d calling `ref` again will have no effect.
288+
The `options` object should contain a `type` field of either `udp4` or `udp6`
289+
and an optional boolean `reuseAddr` field.
319290

320-
Returns `socket`.
291+
When `reuseAddr` is `true` `socket.bind()` will reuse the address, even if
292+
another process has already bound a socket on it. `reuseAddr` defaults to
293+
`false`.
294+
295+
Takes an optional callback which is added as a listener for `message` events.
296+
297+
Call `socket.bind()` if you want to receive datagrams. `socket.bind()` will
298+
bind to the "all interfaces" address on a random port (it does the right thing
299+
for both `udp4` and `udp6` sockets). You can then retrieve the address and port
300+
with `socket.address().address` and `socket.address().port`.
301+
302+
## dgram.createSocket(type[, callback])
303+
304+
* `type` String. Either 'udp4' or 'udp6'
305+
* `callback` Function. Attached as a listener to `message` events.
306+
Optional
307+
* Returns: Socket object
308+
309+
Creates a datagram Socket of the specified types. Valid types are `udp4`
310+
and `udp6`.
311+
312+
Takes an optional callback which is added as a listener for `message` events.
313+
314+
Call `socket.bind()` if you want to receive datagrams. `socket.bind()` will
315+
bind to the "all interfaces" address on a random port (it does the right thing
316+
for both `udp4` and `udp6` sockets). You can then retrieve the address and port
317+
with `socket.address().address` and `socket.address().port`.

0 commit comments

Comments
 (0)