Chinaunix首页 | 论坛 | 博客
  • 博客访问: 560666
  • 博文数量: 493
  • 博客积分: 2891
  • 博客等级: 少校
  • 技术积分: 4960
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 17:11
文章分类

全部博文(493)

文章存档

2010年(493)

分类:

2010-03-29 19:52:31

  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
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/leisure512/archive/2009/11/09/4784704.aspx
 
阅读(826) | 评论(0) | 转发(0) |
0

上一篇:subshell

下一篇:rpc

给主人留下些什么吧!~~