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
在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
相关文章推荐
- Fireprime第一个Linux程序Hello World”
- linux win qt grpc 实现例子
- 使用ARM DS-5 创建、编译和运行Linux简单Hello World应用程序(入门指导)
- Hello World: start running linux
- linux 下RPC 远程过程调用
- Linux下配置RPC框架Apache Thrift
- LinuxC/C++编程基础(31) 使用thrift/rpc开发简单实例(续3)
- 嵌入式linux使用rpc实现多任务过程调用
- Linux操作系统定时任务系统Cron入门、PHP计划任务以及rpc示例
- Linux 最简单内核模块 Hello World 示例
- Linux设备驱动的第一个例子:Hello World
- RPC(linux)报错 Cannot register service RPC
- Linux设备驱动Hello World程序介绍
- LinuxC/C++编程基础(23) 使用thrift/rpc开发简单实例(续1)
- 我的第一个Linux驱动hello world问题记录
- Linux Socket编程实例(一个Hello World程序) 选择自 shaohui 的 Blog
- [分享] Linux下用Anjuta写个Hello World 的C++程序竟如此简单!
- Linux 最简单的驱动程序hello world
- LINUX系统上使用多线程化的RPC
- loadrunner监控linux方式之一:linux下安装rpc.rstatd 篇