BinProlog starting from version 5.40 communicates with
our recently released Java based Linda Interactors special purpose trimmed down pure Prolog engines written
in Java which support the same unification based
Linda protocol as BinProlog.
The natural extension was to allow Java applets
to participate to the rest of our `peer-to-peer'
network of BinProlog interactors.
As creating a server component within a Java applet
is impossible due to Java's (ultra)-conservative
security policies we have simply written a receiving-end
servant close to our
example in subsection
, which relies on a proxy server
on the site where the applet originates from,
for seamless integration in our world of
peer-to-peer interactors.
Here is the code for a more realistic servant, multiplexed among multiple servers and usable inside a Java applet.
run_servant:- default_server_interactor(Interactor), this_id(ID), out(servant_id(ID)), % registers this servant repeat, in(query(ServerId,Query)), % waits for a query (call(Interactor,Query,Reply)->Answer=Reply;Answer=no), % sends back an answer, if needed ( ServerId=[]->true % no reply sent to anonymous servers ; out(answer(ServerId,Answer)) ), functor(Query,stop,_), % stops when required !, in(servant_id(ID)).
Note the presence of an overridable client-side interactor, allowing the generic servant code to be easily reused/specialized. Multiplexing is achieved by having each server's in/1 and out/1 data marked with unique servant_id/1 records.
To integrate multiple Java applet based clients
in our `Web of Worlds', we use a more complex
forwarding server, also available as equivalent Java
code, to be run as a BinProlog and/or Java daemon
on the same machine as the HTTP server the applet comes from.
run_forwarding_server:- server_interactor(forwarding_server_interactor)=>> run_server. forwarding_server_interactor(mes(From,Cs),R):-!,R=yes, forward_to_servants(mes(From,Cs)). forwarding_server_interactor(Q,A):- term_server_interactor(Q,A). forward_to_servants(Query):- clause(servant_id(_),true), assert(query([],Query)), fail. forward_to_servants(_).
Note that the forwarding server has the ability to interact with multiple servants, in particular with multiple Java applets. Starting with version 5.75 this forwarding ability is built in default BinProlog servers started with run_server. Try out the example applet in the corresponding version of the related Java package LindaInteractor available from
http://clement.info.umoncton.ca/~tarau