Write two programs (or one program with two modes) which run on networked computers, and send some messages between them.

The protocol used may be language-specific or not, and should be suitable for general distributed programming; that is, the protocol should be generic (not designed just for the particular example application), readily capable of handling the independent communications of many different components of a single application, and the transferring of arbitrary data structures natural for the language.

This task is intended to demonstrate high-level communication facilities beyond just creating sockets.

open Printf
 
let create_logger () =
  def log(text) & logs(l) =
      printf "Logged: %s\n%!" text;
      logs((text, Unix.gettimeofday ())::l) & reply to log
 
   or search(text) & logs(l) =
      logs(l) & reply List.filter (fun (line, _) -> line = text) l to search
  in
    spawn logs([]);
    (log, search)
 
def wait() & finished() = reply to wait
 
let register name service = Join.Ns.register Join.Ns.here name service
 
let () =
  let log, search = create_logger () in
    register "log" log;
    register "search" search;
    Join.Site.listen (Unix.ADDR_INET (Join.Site.get_local_addr(), 12345));
    wait ()