您的位置:首页 > 运维架构 > Linux

Linux下RPC的hello world

2009-11-08 00:35 211 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: