[ ECLiPSe message passing built-in.|Group Index| Full Index]

mps_receive(+Port, -Message)

Receive a message on the specified port.

+Port
A port identifier (integer)
-Message
A variable

Description

ECLiPSe message passing supports asynchronous non-blocking point-to-point communication in heterogeneous environments. The end-points of communication are ports, i.e. messages are sent to and received from ports. Messages are arbitrary Prolog terms.

mps_receive/2 gets the next incoming message from the specified port. Ports queue incoming messages, and mps_receive/2 takes them out one at a time. If fails if the queue is empty.

The port must have been allocated previously in the same process, using mps_port_allocate/2..

Fail Conditions

Fails if no message available on the port.

Resatisfiable

No.

Exceptions

(4) Instantiation fault
Port is not instantiated
(5) Type error
Port is not an integer
(176)
Message passing system error

Examples

   
% code on server

    server(NsrvHost) :-
	mps_init(NsrvHost),
	mps_port_allocate(true/0, RequestPort),
	mps_port_register("SampleServer", "RunGoal", "Sig", RequestPort),
	server_loop(RequestPort).

    server_loop(RequestPort) :-
	repeat,
	    mps_receive(RequestPort, request(Goal, ReplyPort)),
	    once(Goal),
	    mps_send(ReplyPort, Goal),
	fail.

% code on client

    client_init(NsrvHost, RequestPort-ReplyPort) :-
	mps_init(NsrvHost),
	mps_port_allocate(true/0, ReplyPort),
	repeat,
	    mps_port_lookup("SampleServer", "RunGoal", RequestPort),
	!.

    remote_once(RequestPort-ReplyPort, Goal) :-
	mps_send(RequestPort, request(Goal, ReplyPort)),
	repeat,
	    mps_receive(ReplyPort, Reply),
	!,
	Goal = Reply.

% Sample session (client side):

    [eclipse 1]:  [client].
    client.pl  compiled traceable 624 bytes in 0.00 seconds
    yes.
    [eclipse 2]: client_init(breeze, Ports),
                 remote_once(Ports, X is 3+4).

    Ports = 794820612 - 364511236
    X = 7
    yes.




See Also

mps_init / 1, mps_ping / 1, mps_exit / 0, mps_port_register / 4, mps_port_lookup / 3, mps_port_deregister / 3, mps_port_allocate / 2, mps_port_deallocate / 1, mps_send / 2