/usr/lib/swipl/library/ext/clib/socket.pl
All Application Manual Name SummaryHelp

  • ext
    • clib
      • socket.pl -- Network socket (TCP and UDP) library
        • socket_create/2
        • tcp_socket/1
        • unix_domain_socket/1
        • tcp_close_socket/1
        • tcp_open_socket/2
        • tcp_open_socket/3
        • tcp_bind/2
        • tcp_listen/2
        • tcp_accept/3
        • tcp_connect/2
        • rewrite_host/3
        • tcp_connect/4
        • tcp_connect/3
        • tcp_select/3
        • try_proxy/4
        • proxy_for_url/3
        • udp_socket/1
        • udp_receive/4
        • udp_send/4
        • tcp_setopt/2
        • tcp_fcntl/3
        • tcp_getopt/2
        • host_address/3
        • tcp_host_to_address/2
        • gethostname/1
        • ip_name/2
        • negotiate_socks_connection/2
      • uid.pl
      • unix.pl -- Unix specific operations
      • syslog.pl -- Unix syslog interface
      • memfile.pl
      • time.pl -- Time and alarm library
      • uri.pl -- Process URIs
      • filesex.pl -- Extended operations on files
      • uuid.pl -- Universally Unique Identifier (UUID) Library
      • sha.pl -- SHA secure hashes
      • process.pl -- Create processes and redirect I/O
      • hash_stream.pl -- Maintain a hash on a stream
      • md5.pl -- MD5 hashes
      • rlimit.pl
      • mallocinfo.pl -- Memory allocation details
      • prolog_stream.pl -- A stream with Prolog callbacks
      • prolog_server.pl
      • udp_broadcast.pl -- A UDP broadcast proxy
      • crypt.pl
      • streaminfo.pl
      • streampool.pl -- Input multiplexing
      • cgi.pl -- Read CGI parameters
 udp_send(+Socket, +Data, +To, +Options) is det
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 an IP address. Defined Options are:
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 to CVT_ALL of PL_get_chars(). Using atom corresponds to CVT_ATOM and any of string or codes is mapped to CVT_STRING|CVT_LIST, allowing for a SWI-Prolog string object, list of character codes or list of characters. Finally, term maps to CVT_WRITE_CANONICAL. This implies that arbitrary Prolog terms can be sent reliably using the option list `[as(term),encoding(utf8)])`, using the same option list for udp_receive/4.

For example

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.