| Starts a thread listening for input from a binary input stream
listener_start(+Stream, +Callback, -Listener)
listener_start/3 starts a thread listening for input from a
a binary input stream Stream. The input has to be send
with the predicate send/2. When a input term has been read,
the callback predicate Callback will be called. If the
first argument of Callback is a variable, then it is replaced
by the term, that has been read. If the second argument of Callback
is a variable then it will be replaced by the listener object.
Arguments
Stream binary input stream
Callback compound or atom
Listener object
Examples
main(_) :-
server_start(1352, 3, accept_connection(_), _).
accept_connection(Socket) :-
open(Socket, read, Input, [socket,buffered,binary]),
open(Socket, write, Output, [socket,buffered,binary]),
listener_start(Input, handle_request(_, _, Input, Output), _).
handle_request(logoff, Listener, Input, Output) :- !,
close(Input),
close(Output),
listener_stop(Listener).
handle_request(Request, Listener, Input, Output) :-
...
See also
server_start/4,
server_stop/1,
client_start/3,
client_stop/1,
listener_start/3,
listener_stop/1,
send/2,
receive/2.
|