• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

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

  • ext
    • clib
      • socket.pl
      • uid.pl
      • unix.pl -- Unix specific operations
      • syslog.pl -- Unix syslog interface
      • filesex.pl -- Extended operations on files
      • uri.pl -- Process URIs
      • process.pl -- Create processes and redirect I/O
      • time.pl -- Time and alarm library
      • sha.pl -- SHA secure hashes
      • crypt.pl
      • memfile.pl
      • uuid.pl -- Universally Unique Identifier (UUID) Library
      • hash_stream.pl -- Maintain a hash on a stream
      • md5.pl -- MD5 hashes
      • udp_broadcast.pl -- A UDP broadcast proxy
        • udp_broadcast_close/1
        • udp_broadcast_initialize/2
        • udp_peer_add/2
        • udp_peer_del/2
        • udp_peer/2
        • udp_term_string_hook/3
        • udp_unicast_join_hook/3
      • streampool.pl -- Input multiplexing
      • cgi.pl -- Read CGI parameters
      • prolog_stream.pl -- A stream with Prolog callbacks
      • rlimit.pl
 udp_unicast_join_hook(+Scope, +From, +Data) is semidet[multifile, library(udp_broadcast)]
This multifile hook is called if an UDP package is received on the port of the unicast network identified by Scope. From is the origin IP and port and Data is the message data that is deserialized as defined for the scope (see udp_term_string/3).

This hook is intended to initiate a new node joining the network of peers. We could in theory also omit the in-scope test and use a normal broadcast to join. Using a different channal however provides a basic level of security. A possibe implementation is below. The first fragment is a hook added to the server, the second is a predicate added to a client and the last initiates the request in the client. The excanged term (join(X)) can be used to exchange a welcome handshake.

:- multifile udp_broadcast:udp_unicast_join_hook/3.
udp_broadcast:udp_unicast_join_hook(Scope, From, join(welcome)) :-
    udp_peer_add(Scope, From),
join_request(Scope, Address, Reply) :-
    udp_peer_add(Scope, Address),
    broadcast_request(udp(Scope, join(X))).
?- join_request(myscope, "1.2.3.4":10001, Reply).
Reply = welcome.
ClioPatria (version V3.1.1-51-ga0b30a5)