in this article, three point should be marked, first is the gen_server, then State, final call and cast.

first gen_server:

-module(eb_server).

%% API

-export([start_link/0,create_acount/2,deposit/2,withdraw/2,delete_account/1,authorize/2]).


%% internal callbacks

-export([init/1,handle_call/3,handle_cast/2,handle_info/2,terminate/2,code_change/3]).


-define(SERVER, ?MODULE).


start_link() ->
  gen_server:start_link({local, ?SERVER}, ?MODULE, [], []).


init([]) ->

{ok, dict:new()}.


create_account(name, PIN) ->

gen_server:cast(?SERVER, {create, name, PIN}).


handler_cast({create, Name, PIN}, State) ->

{noreply, dict:store(Name, {PIN,0}, State)};


above is the complete min server model


when application is start, start will called first, start_new_game is a open api for user to start a new game app.

eggs_service:start_game is the final call for start the game. 


run -> send data to game server.


if the game client pass data through inet, the code should be 


example_game_gateway_socket:test_bots

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐