主页 > 其他 > 初试json rpc

初试json rpc

2017年4月28日 初试json rpc无评论 阅读: 13,841 次

目标:
用C语言实现json rpc server,通过http作为客户端来获取信息

参考:
12

编译过程:
下载:
git clone https://github.com/hmng/jsonrpc-c
cd jsonrpc-c
在Ubuntu下编译,先安装依赖库
sudo apt install libev-dev autoconf
配置:
autoreconf -i
./configure
编译:
make

生成的程序在~/jsonrpc-c/example/server

运行程序
~/jsonrpc-c/example/server
程序在1234端口进行监听

测试:
echo "{\"method\":\"sayHello\"}" | nc localhost 1234

交叉编译:
要编译出适合ARM系统运行的程序
1、首先编译libev
12
ver=4.24
wget http://dist.schmorp.de/libev/libev-$ver.tar.gz
tar zxf libev-$ver.tar.gz
cd libev-$ver
./configure --host=arm-linux --prefix=/opt/lib/libev --enable-shared
make && make install

2、再编译jsonrpc
先配置,注意指定libev的目录:
./configure --host=arm-linux --with-libev=/opt/lib/libev
编译
make
搞定:
2017-04-29 10-57-00
生成的程序~/jsonrpc-c/example/server是一个脚本程序,真正的程序在~/jsonrpc-c/example/.libs,包含两个程序lt-server、server,这两个程序调用了动态链接库libjsonrpcc.so
3、静态链接
要使用静态链接库,在配置libev时:
./configure --host=arm-linux --prefix=/opt/lib/libev -enable-static --disable-shared
在配置jsonrpc时:
./configure --host=arm-linux --with-libev=/opt/lib/libev --enable-static --disable-shared

手动编译libev的用户程序
比如程序源文件为libtest.c,编译用于ubuntu下的程序:
gcc libevtest.c /usr/lib/x86_64-linux-gnu/libev.so -o libevtest
编译用于arm的程序:
arm-linux-gcc -I/opt/lib/libev/include/ libevtest.c /opt/lib/libev/lib/libev.so -o libevtest_arm

发表评论

新用户的评论需审核后才会显示;

电子邮件地址不会被公开;
必填项已用*标注