Represents a UDP socket.
Instances For
Creates a new UDP socket.
Binds an UDP socket to a specific address. Address reuse is enabled to allow rebinding the same address.
Associates the UDP socket with the given address and port, so every message sent by this socket is automatically sent to that destination.
Sends data through an UDP socket. The addr
parameter specifies the destination address. If addr
is none
, the data is sent to the default peer address set by connect
.
Receives data from an UDP socket. size
is for the maximum bytes to receive. The promise
resolves when some data is available or an error occurs.
Furthermore calling this function in parallel with waitReadable
is not supported.
Returns an IO.Promise
that resolves once socket
has data available for reading. Calling this
function twice on the same Socket
or in parallel with recv
is not supported.
Cancels a receive operation in the form of recv
or waitReadable
if there is currently one
pending. This resolves their returned IO.Promise
to none
. This function is considered dangerous,
as improper use can cause data loss, and is therefore not exposed to the top-level API.
Note that this function is idempotent and as such can be called multiple times on the same socket
without causing errors, in particular also without a receive running in the first place.
Receives data from an UDP socket. size
is for the maximum bytes to receive. The promise resolves
when some data is available or an error occurs. If the socket has not been previously bound with bind
,
it is automatically bound to 0.0.0.0
(all interfaces) with a random port.
Gets the local address of a bound UDP socket.
Sets the membership for joining or leaving a multicast group. If interfaceAddr
is none
, the
default network interface is used.
Sets the multicast interface for sending packets.