Associates a UDP port number (Port) with the calling process. It returns
{ok, Socket}, or {error, Reason}. The returned Socket is used to
send packets from this port with the send/4 function. Options is a list of options
associated with this port.

When UDP packets arrive at the opened Port they will be delivered as messages of the type
{udp, Socket, IP, InPortNo, Packet}

IP and InPortNo define the address
from which Packet came. Packet is a list of bytes if the
option list was specified. Packet is a binary if the option binary was
specified.

The available options are:

list

Received Packet is delivered as a list.

binary

Received Packet is delivered as a binary.

common inet options

The common inet options available are described in the
setopts/2 function
in the inet manual page.

If you set Port to 0, the underlying Operating System assigns a free UDP port. (You can find out which port by calling inet:port(Socket).)

If any of the following functions are called with a Socket that was not opened by
the calling process, they will return {error,not_owner}.
The ownership of a Socket can be transferred to another process
with controlling_process/2.

Sends Packet to the specified address (address, port). It
returns ok, or {error, Reason}. Address can be an
IP address expressed as a tuple, for example {192, 0, 0, 1}. It can also be a host name expressed as an atom or a string, for example 'somehost.some.domain'.
Port is an integer, and Packet is either a list of bytes or
a binary.