简单的gen_server Hello World程序
代码:
-module(genserver).
-behaviour(gen_server).
-export([start/0, hello/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
start() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
hello(Name) ->
Reply = gen_server:call(?MODULE, {hello, Name}),
io:format("~s~n", [Reply]).
handle_call({hello, Name}, _From, State) ->
Reply = lists:append(["Hello, ", Name, "!"]),
{reply, Reply, State}.
init(_Args) ->
{ok, init}.
handle_cast(_Request, State) ->
{noreply, State}.
handle_info(_Info, State) ->
{noreplay, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
编译:
Eshell> c(genserver).
运行:
Eshell> genserver:start().
Eshell> genserver:hello("Hideto").
输出结果:
Hello, Hideto!
分享到:
相关推荐
gen_lex_hash for pc,mysql交叉编译需要用到的文件,5.1.51 and 5.1.63两个版本,5.1.67版本始终编译不出来。有需要的下载。
通用 TCP 服务器 通用 TCP 服务器( gen_tcp_server ) 是一种 Erlang 行为,提供快速简便的方法将 TCP 服务器功能添加到您的应用程序。 它被实现为管理 TCP 连接的主管,因为它是孩子。如何使用它? 运行make来构建。...
Gen_Signature_Android2.apk、获取签名工具。
NULL 博文链接:https://lzy.iteye.com/blog/324962
Gen_Signature_Android.apk
关于在 Erlang 风格的 gen_server 上进行 Ocaml/Async 尝试。
包名签名查看,输入包名则可查看签名值,用于微信第三方分享 登录等设置填写,安装则可以使用,没需要任何设置,可以在安卓模拟器上使用
华硕Z87-C主板升级BIOS的工具,BIOS_updater_for_4th_Gen_Intel_Core_CPU.zip
个人学习Erlang的时候自己写的一个基于gen_tcp的聊天室,功能有注册,登陆,获得登陆时间,聊天次数,上次登陆时间等等,资源里有完整代码,注释也很详细.
srio_response_gen_srio_gen2_0_srio_gen_srio_reponse_SRIO_gen2_SR
gen_lyricist.dll 万能播放器仿千千静听
1、将2560及ramps1.4集合在一块板子上,解决了Ramps1.4组合接口繁琐,易出故障的问题。 2、可更换电机驱动,支持4988驱动和8825驱动。 3、电路板采用高质量的4层板,并专门作了散热优化处理;...
采用verilog实现RTLAB多路驱动程序
pwm_gen,PWN波形发生器,开关波形
erlang-gen_tcp手册,详细完整,网络tcp开发好东东
K210的机器码生成固件,来自https://en.bbs.sipeed.com/uploads/default/original/1X/bca0832bed92a1ada63bd05327688784e2ef14d1.zip