客户端-服务器端(C/S)模型的特点是:一个中央服务器和任意数量的客户端。C/S模型通常用于资源管理操作,其中一些不同的客户端要共享一个公共资源。服务器负责管理这些资源。
服务器可以用 gen_server 进行重写,结果产生这个回调模块:
-module(ch3).
-behaviour(gen_server).
-export([start_link/0]).
-export([alloc/0, free/1]).
-export([init/1, handle_call/3, handle_cast/2]).
start_link() ->
gen_server:start_link({
local, ch3}, ch3, [],