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