天天看點

Erlang行為模式實作子產品的首部

%%%-------------------------------------------------------------------

%%% @author Martin & Eric <[email protected]>    %作者資訊和郵箱位址

%%%  [http://www.erlware.org]

%%% @copyright 2008-2010 Erlware                                                       %日期和版權歸屬

%%% @doc RPC over TCP server. This module defines a server process that

%%%      listens for incoming TCP connections and allows the user to

%%%      execute RPC commands via that TCP stream.                     %正常文檔文本,概要描述

%%% @end    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​         %标志着标簽的完結

%%%-------------------------------------------------------------------

-module(tr_server).

-behaviour(gen_server).

-include_lib("eunit/include/eunit.hrl").

%% API

-export([

         start_link/1,

         start_link/0,

         get_count/0,

         stop/0

         ]).

%% gen_server callbacks

-export([init/1, handle_call/3, handle_cast/2, handle_info/2,

         terminate/2, code_change/3]).

-define(SERVER, ?MODULE).    ​    ​    ​    ​    ​    ​    ​    ​    ​    ​ %将SERVER設定為子產品名

-define(DEFAULT_PORT, 1055).    ​    ​    ​    ​    ​    ​    ​    ​     %定義預設端口

-record(state, {port, lsock, request_count = 0}).    ​    %​用于儲存程序狀态

繼續閱讀