6.5 UDP protocol support
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog C-library
        • library(socket): Network socket (TCP and UDP) library
          • UDP protocol support
            • udp_socket/1
            • udp_receive/4
            • udp_send/4
Availability::- use_module(library(socket)).(can be autoloaded)
Sourceudp_send(+Socket, +Data, +To, +Options)
Send a UDP message. Data is a string, atom or code-list providing the data. To is an address of the form Host:Port where Host is either the hostname or a term ip/4. Options is currently unused.

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.