Giter VIP home page Giter VIP logo

youyoujushi / aic_communication Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aicrobo/aic_communication

1.0 1.0 0.0 808 KB

aic_commu library 是一个基于 libzmq 以及 protobuf 封装而成的通讯库。主要提供心跳、自动重连等一些网络状态检测以及恢复功能,支持请求应答、订阅发布两种模式。

License: MIT License

CMake 0.40% C++ 99.42% C 0.18%

aic_communication's Introduction

aic_commu library

Description

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.


QUICK START

  • 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);

DEPENDS:

  • Windows 10, Linux
  • CMake 3.5 (on Linux & Windows)
  • Visual Studio 2015 Update 3 (on Windows)
  • C compiler and GNU C++ compiler (on Linux)
  • libzmq-master(commit 12005bd92629c2cca108ae1731a495e93a3aef91)

BUILD(linux):

  1. download aic_communication source code。
  2. download libzmq source code libzmq
  3. build zmq to static library
cd libzmq
./autogen.sh
./configure --enable-static --with-pic 
make
sudo make install
  1. build aic_communication
cd  aic_communication
mkdir build 
cd build 
cmake .. 
make
sudo make install
  1. build example
  • in step 4,replace cmake .. with
    • cmake .. -DTEST_JSON=YES (only build json version example )
    • cmake .. -DTEST_PROTOBUF=YES (only build protobuf version example)
    • cmake .. -DTEST=YES (build all version example)

BUILD(windows):

  1. download aic_communication source code。
  2. download libzmq source code libzmq
  3. build zmq
cd  aic_communication/builds
mkdir windows 
cd windows 
cmake ../.. 
double click libzmq.vcxprojbuild dll and lib
  1. build aic_communication
cd aic_communication
mkdir build
cmake ..
double click aic_commu.slnright click aic_commu projectclick propertyconfig header and lib file paths of zmq and protobufbuild aic_commu.dll and aic_commu.lib
  1. build example
  • in step 4,replace cmake .. with
    • cmake .. -DTEST_JSON=YES (only build json version example )
    • cmake .. -DTEST_PROTOBUF=YES (only build protobuf version example)
    • cmake .. -DTEST=YES (build all version example)
  • notice: if you build protobuf version example,you must download and build protobuf first, then run commands:'cd example/protobuf' 'protoc --cpp_out=. packet.proto'.then you will get two new files:packet.pb.h,packet.pb.cc

USING

prepare:config right ips in source code,rebuild project

request-reply mode

  • open one console,run req_json or req_proto
  • open another console,run rep_json or rep_proto

publish-subscribe mode

  • open one console,run sub_json or sub_proto
  • open another console,run pub_json or pub_proto

notice: *_json and _json is a pair,_proto and *_proto is a pair,you can't run one *_json and one *_proto

-----------VERSION LOG-----------

1.2 version

  • update:
  • remove libprotobuf dependence

1.1.7 version

  • fix bugs:

  • fix bug what you never can send and recv data after request timeout when in request mode。

  • fix bug what deadlock caused by socket destruction。

  • new functions:

  • add param to send function,it will discard send packet when connect with server hasn't build。

Copyright (c) 2018, AicRobo. All rights reserved.

aic_communication's People

Contributors

youyoujushi avatar guohefu avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.