Linux下RPC的hello world

Linux 下面使用RPC需要使用到命令rpcgen.
在Linux下开发RPC程序流程如下:
1.写一个rpc程序,

       如test.x
2.使用rpcgen生成必须的文件,通常是客户端和服务器端以及头文件

       $rpcgen test.x
3.使用rpcgen生成服务器端和客户端的C语言代码

       $rpcgen -Ss -o test_server.c  test.x

       $rpcgen -Sc -o test_client.c  test.x
4.编辑源文件,加入你想要的服务等
5.使用gcc编译生成可执行文件

       $gcc -Wall -o test_server test_server.c test_clnt.c test_srv.c

       $gcc -Wall -o test_client  test_clnt.c test_client.c

6.使用rpcgen生成Makefile

       $rpcgen -Sm test.x>Makefile
7.执行测试

       $./test_server

       $./test_client 127.0.0.1
问题:
1.服务器无法启动,错误如下:
Cannot register service: RPC: Unable to receive; errno = Connection refused
unable to register (TESTPROG, VERSION, udp).


解决方法:系统没有安装portmap或者没有启动portmap端口映射。
$ls /etc/init.d/    
如果没有portmap则安装之
    $sudo apt-get install portmap
如果有了,则启动
    $sudo /etc/init.d/portmap start
还可以使用chkconfig设置系统开机启动的服务项,如将portmap加入开机启动:
    $sudo chkconfig --level 2 -s portmap on

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值