rpcgen: c语言实现远程过程调用

Those who do not understand Unix are condemned to reinvent it, poorly.

不懂Unix 的人注定最终还要重复发明一个蹩脚的Unix 。

                                                                        Usenet 签名, 1987 年11 月 ——Henry Spencer

1. 如何使用rpc?


先要安装rpcbind库(可能需要portmap支持)
apt-get install rpcbind

2. 查看rpcbind中注册的服务

使用rpcinfo命令, 可以使用man rpcinfo查看参数用法,默认如下或者带上参数-p,都是本地host的信息.

3. rpcgen的简单讲解及例子程序


3.1 创建规格文件(test.x)

/* filename: test.x */

const ADD = 0;
const SUB = 1;
const MUL = 2;
const DIV = 3;

struct TEST
{
    int op; /* 0-ADD, 1-SUB, 2-MUL, 3-DIV */
    float arg1;
    float arg2;
    float result;
};

program TEST_PROG
{
    version TEST_VER
    {
        struct TEST TEST_PROC(struct TEST) = 1;
    } = 2;
} = 0x20000001;
/* filename: test.x */

3.2 用 rpcgen -C -a test.x  生成7个文件


Makefile.test test_client.c test_clnt.c test.h test_server.c test_svc.c test_xdr.c

3.3 修改test_client.c & test_server.c文件:

参考https://www.jianshu.com/p/b33fc01c1f59


3.4 添加完成后执行

make -f Makefile.test
3.5 在命令行运行  

$ ./test_server  
$ ./test_client 127.0.0.1

https://command-not-found.com/rpcinfo
https://www.tutorialspoint.com/unix_commands/rpcgen.htm
https://www.jianshu.com/p/b33fc01c1f59
 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值