aic_commu library 是一个基于 libzmq 以及 protobuf 封装而成的通讯库。主要提供心跳、自动重连等一些网络状态检测以及恢复功能,支持请求应答、订阅发布两种模式。
Aic_commu library is a communication library based on libzmq. It mainly provides some network status detection and recovery functions, such as heartbeat detection, disconnection or automatic reconnection of heartbeat timeout. It supports two modes: request response and subscription publishing.
Using this library is simpler than programming directly with zmq, shielding many underlying details, and transferring data between business layer and communication library through callback function, so that callers only care about business logic.
request client
auto obj = AicCommuFactory::newSocket(AicCommuType::CLIENT_REQUEST, "127.0.0.1", 60005, "req");
obj->setRecvCall(&req_recv_func, false);
obj->run();
sting msg = "test req msg";
bytes_ptr pack = std::make_shared<bytes_vec>(msg.data(),msg.data()+msg.size());
obj->send();
response server
auto obj = AicCommuFactory::newSocket(AicCommuType::SERVER_REPLY, "*", 60005, "rep");
obj->setRecvCall(&rep_recv_func, false);
obj->run();
subscribe client
auto obj = AicCommuFactory::newSocket(AicCommuType::CLIENT_SUBSCRIBE, "127.0.0.1", 60006, "sub");
obj->setRecvCall(&sub_recv_func, false);
obj->run();
obj->alterSubContent("sub-test", true);
publish server
auto obj = AicCommuFactory::newSocket(AicCommuType::SERVER_PUBLISH, "*", 60006, "pub");
obj->run();
std::string msg = "test pub msg";
bytes_ptr pack = std::make_shared<bytes_vec>(msg.data(),msg.data() + msg.length());
obj->publish("sub-test", pack);
cd libzmq
./autogen.sh
./configure --enable-static --with-pic
make
sudo make install
build aic_communication
cd aic_communication
mkdir build
cd build
cmake ..
make
sudo make install
build example
cd aic_communication/builds
mkdir windows
cd windows
cmake ../..
double click libzmq.vcxproj,build dll and lib
cd aic_communication
mkdir build
cmake ..
double click aic_commu.sln,right click aic_commu project,click property,config header and lib file paths of zmq and protobuf,build aic_commu.dll and aic_commu.lib。
prepare:config right ips in source code,rebuild project
request-reply mode
publish-subscribe mode
notice: _json and _json is a pair,_proto and _proto is a pair,you can’t run one _json and one _proto
fix bugs:
new functions:
Copyright (c) 2018, AicRobo. All rights reserved.