Erlang行为模式实现模块的首部

本文概述了一个基于TCP的RPC服务器的实现,包括启动链接、处理调用、消息传递和终止过程,以及如何通过TCP流执行RPC命令。

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

%%% @author Martin & Eric <erlware-dev@googlegroups.com>    %作者信息和邮箱地址

%%%  [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}).    ​    %​用于保存进程状态


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值