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
:- multifile udp_broadcast:udp_unicast_join_hook/3.
udp_broadcast:udp_unicast_join_hook(Scope, From, join(welcome)) :-
join_request(Scope, Address, Reply) :-
?- join_request(myscope, "220.127.116.11":10001, Reply).
Reply = welcome.