Erlang rpc函数初学

来源:互联网 发布:数修改数据库语句名称 编辑:程序博客网 时间:2024/06/06 04:20
刚开始学Erlang的函数调用,昨天晚上一直不知道rpc这个功能到底是什么的,今天敲了一下,原来是这么一回事:
-module(area_server1).-export([loop/0,rpc/2]).rpc(Pid,Request) ->    Pid ! {self(),Request}, %%这是向指定Pid发送请求的    receive  %%这个是接收响应结果的        Response -> io:format("The answer is ~p~n",[Response])    end.loop() ->    receive        {From,{rec,Width,Ht}} ->             From ! Width*Ht,            loop();        {From,{circle,R}} ->             From ! 3.14*R,            loop();        {From,Other}->            From ! {error,Other},            loop()    end.~                
rpc的receive就是就是接受来自指定Pid发过来的信号的,原文中:就就是不做任何处理的把返回结果打印出来。
receive      Response -> Responseend.

	
				
		
原创粉丝点击