Skip to content
/ rpclib Public
forked from dboltovskyi/rpclib

rpclib is a modern C++ msgpack-RPC server and client library

License

Notifications You must be signed in to change notification settings

livio/rpclib

This branch is up to date with dboltovskyi/rpclib:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

82f018e · Mar 25, 2019
Oct 25, 2017
Mar 18, 2017
Oct 26, 2017
Jul 25, 2017
Oct 27, 2017
Jun 4, 2016
Mar 25, 2019
Oct 27, 2017
Oct 26, 2017
Jan 13, 2016
Apr 25, 2016
Oct 25, 2017
Oct 25, 2017
Jun 4, 2016
Oct 28, 2017
Oct 28, 2017
Mar 16, 2017
Oct 26, 2017
Oct 26, 2017
Oct 25, 2017
Oct 25, 2017
Oct 25, 2017
Feb 15, 2016

Repository files navigation

rpclib MIT Build Status Build status Coverage Status Coverity Gitter

waffle

rpclib is a RPC library for C++, providing both a client and server implementation. It is built using modern C++14, and as such, requires a recent compiler. Main highlights:

  • Expose functions of your program to be called via RPC (from any language implementing msgpack-rpc)
  • Call functions through RPC (of programs written in any language)
  • No IDL to learn
  • No code generation step to integrate in your build, just C++

Look&feel

Server

#include <iostream>
#include "rpc/server.h"

void foo() {
    std::cout << "foo was called!" << std::endl;
}

int main(int argc, char *argv[]) {
    // Creating a server that listens on port 8080
    rpc::server srv(8080);

    // Binding the name "foo" to free function foo.
    // note: the signature is automatically captured
    srv.bind("foo", &foo);

    // Binding a lambda function to the name "add".
    srv.bind("add", [](int a, int b) {
        return a + b;
    });

    // Run the server loop.
    srv.run();

    return 0;
}

When srv.run() is called, rpclib starts the server loop which listens to incoming connections and tries to dispatch calls to the bound functions. The functions are called from the thread where run was called from. There is also async_run that spawns worker threads and returns immediately.

Client

#include <iostream>
#include "rpc/client.h"

int main() {
    // Creating a client that connects to the localhost on port 8080
    rpc::client client("127.0.0.1", 8080);

    // Calling a function with paramters and converting the result to int
    auto result = client.call("add", 2, 3).as<int>();
    std::cout << "The result is: " << result << std::endl;
    return 0;
}

Status

All planned 1.0.0 features are done and tested; the current state is production-ready.

Who uses rpclib?

This list is updated as I learn about more people using the library; let me know if you don't want your project listed here.

Thanks

rpclib builds on the efforts of fantastic C++ projects. In no particular order:

Shoutouts to

About

rpclib is a modern C++ msgpack-RPC server and client library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 94.4%
  • C 4.8%
  • Other 0.8%