- encoding(Encoding)
- Specifies the encoding to use for the string. See udp_receive/4 for details.
- as(Type)
- This uses the same values for Type as the
as(Type)
option of udp_receive/4. The are interpreted differently though. No Type corresponds toCVT_ALL
of PL_get_chars(). Usingatom
corresponds toCVT_ATOM
and any ofstring
orcodes
is mapped toCVT_STRING|CVT_LIST
, allowing for a SWI-Prolog string object, list of character codes or list of characters. Finally,term
maps toCVT_WRITE_CANONICAL
. This implies that arbitrary Prolog terms1write_canonical/2 does not support blobs nor cyclic terms can be sent reliably using the option list[as(term),encoding(utf8)])
, using the same option list for udp_receive/4.
A simple example to send UDP data is:
send(Host, Port, Message) :- udp_socket(S), udp_send(S, Message, Host:Port, []), tcp_close_socket(S).
A broadcast is achieved by using tcp_setopt(Socket, broadcast)
prior to sending the datagram and using the local network broadcast
address as a ip/4
term.