doc: dgram: reword dgram.Socket#send() docs

Make it clear that the address argument is not really optional and fix
some Engrish and long lines while we're here.

Fixes #6433.
pull/5010/head
Ben Noordhuis 2013-10-29 10:31:14 +01:00
parent 4b5e6a38df
commit 0c5981b226
1 changed files with 17 additions and 13 deletions

View File

@ -72,21 +72,25 @@ Emitted when an error occurs.
* `buf` Buffer object. Message to be sent * `buf` Buffer object. Message to be sent
* `offset` Integer. Offset in the buffer where the message starts. * `offset` Integer. Offset in the buffer where the message starts.
* `length` Integer. Number of bytes in the message. * `length` Integer. Number of bytes in the message.
* `port` Integer. destination port * `port` Integer. Destination port.
* `address` String. destination IP * `address` String. Destination hostname or IP address.
* `callback` Function. Callback when message is done being delivered. * `callback` Function. Called when the message has been sent. Optional.
Optional.
For UDP sockets, the destination port and IP address must be specified. A string For UDP sockets, the destination port and address must be specified. A string
may be supplied for the `address` parameter, and it will be resolved with DNS. An may be supplied for the `address` parameter, and it will be resolved with DNS.
optional callback may be specified to detect any DNS errors and when `buf` may be
re-used. Note that DNS lookups will delay the time that a send takes place, at
least until the next tick. The only way to know for sure that a send has taken place
is to use the callback.
If the socket has not been previously bound with a call to `bind`, it's If the address is omitted or is an empty string, `'0.0.0.0'` or `'::0'` is used
assigned a random port number and bound to the "all interfaces" address instead. Depending on the network configuration, those defaults may or may not
(0.0.0.0 for `udp4` sockets, ::0 for `udp6` sockets). work; it's best to be explicit about the destination address.
If the socket has not been previously bound with a call to `bind`, it gets
assigned a random port number and is bound to the "all interfaces" address
(`'0.0.0.0'` for `udp4` sockets, `'::0'` for `udp6` sockets.)
An optional callback may be specified to detect DNS errors or for determining
when it's safe to reuse the `buf` object. Note that DNS lookups delay the time
to send for at least one tick. The only way to know for sure that the datagram
has been sent is by using a callback.
Example of sending a UDP packet to a random port on `localhost`; Example of sending a UDP packet to a random port on `localhost`;