在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:cinemast/libjson-rpc-cpp开源软件地址:https://github.com/cinemast/libjson-rpc-cpp开源编程语言:C++ 93.3%开源软件介绍:I created a new C++17 header only implementation -> json-rpc-cxx. libjson-rpc-cppThis framework provides cross platform JSON-RPC (remote procedure call) support for C++. It is fully JSON-RPC 2.0 & 1.0 compatible. 5 good reasons for using libjson-rpc-cpp in your next RPC project
Other good reasons to use libjson-rpc-cpp
OverviewInstall the frameworkDebian (stretch) and Ubuntu (15.10 or later) sudo apt-get install libjsonrpccpp-dev libjsonrpccpp-tools Fedora sudo dnf install libjson-rpc-cpp-devel libjson-rpc-cpp-tools Arch Linux For Arch Linux there is a PKGBUILD provided in the AUR. sudo aura -A libjson-rpc-cpp Gentoo Linux sudo emerge dev-cpp/libjson-rpc-cpp Mac OS X For OS X a Brew package is available: brew install libjson-rpc-cpp Windows There is a ready to use compiled package here. Just download execute the installer EXE. Build from sourceInstall the dependenciesUNIX For Debian and Arch GNU/Linux based systems, all dependencies are available via the package manager. For OS X all dependencies are available in Brew Buildgit clone https://github.com/cinemast/libjson-rpc-cpp.git
mkdir -p libjson-rpc-cpp/build
cd libjson-rpc-cpp/build
cmake .. && make
sudo make install
sudo ldconfig #only required for linux That's it! If you are not happy with it, simply uninstall it from your system using (inside the build the directory): sudo make uninstall Build options: Default configuration should be fine for most systems, but here are available compilation flags:
Using the frameworkThis example will show the most simple way to create a rpc server and client. If you only need the server, ignore step 4. If you only need the client, ignore step 3. You can find all resources of this sample in the Step 1: Writing the specification file[
{
"name": "sayHello",
"params": {
"name": "Peter"
},
"returns" : "Hello Peter"
},
{
"name" : "notifyServer"
}
] The type of a return value or parameter is defined by the literal assigned to it. The generated stubs will will use the "returns" type to validate the response. In this example you can see how to specify methods and notifications. Step 2: Generate the stubs for client and serverCall jsonrpcstub: jsonrpcstub spec.json --cpp-server=AbstractStubServer --cpp-client=StubClient
mkdir -p gen
mv abstractstubserver.h gen
mv stubclient.h gen This generates an Step 3: implement the abstract server stubExtend the abstract server stub and implement all pure virtual (abstract) methods defined in See src/examples/stubserver.cpp In the main function the concrete server is instantiated and started. That is all for the server. Any JSON-RPC 2.0 compliant client can now connect to your server. Compile the server with: g++ stubserver.cpp -ljsoncpp -lmicrohttpd -ljsonrpccpp-common -ljsonrpccpp-server -o sampleserver Step 4: Create the client applicationSee src/examples/stubclient.cpp Compile the client with: g++ stubclient.cpp -ljsoncpp -lcurl -ljsonrpccpp-common -ljsonrpccpp-client -o sampleclient ContributionsPlease take a look at CONTRIBUTING.md ChangelogsChangelogs can be found here. API compatibilityWe do our best to keep the API/ABI stable, to prevent problems when updating this framework. A compatiblity report can be found here. LicenseThis framework is licensed under MIT. All of this libraries dependencies are licensed under MIT compatible licenses. References
If you use this library and find it useful, I would be very pleased if you let me know about it. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论