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


rpclib MIT Build Status Build status Coverage Status Coverity Gitter


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++



#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.

    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.


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

int main() {
    // Creating a client that connects to the localhost on port 8080
    rpc::client client("", 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;


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.


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

Shoutouts to

  • Rewrite cmake script

    Rewrite cmake script

    CMake is building 32-bit build even when executed from "Visual Studio 2015 x64 native Tools" command prompt. I'd to do following to get 64-bit build. It might be nice to include this in documentation.

    1. Go to "Visual Studio 2015 x64 native Tools" command prompt. Make sure you have VS2015 Update 3.
    2. cmake -G"Visual Studio 14 2015 Win64" ..
    3. cmake --build .

    This will generate Debug build. To get the release build do cmake --build . --config Release.

    opened by sytelus 14
  • Project still alive

    Project still alive

    I've only recently learned about this library and initial tests look very promising. However, given that the last commit seems to be over a year ago I was wondering if this project is still alive.

    opened by MBalszun 12
  • Dependency build issue: format.cc

    Dependency build issue: format.cc

    I'm running into a build error due to the format.cc dependency found here:

    dependencies/src/format.cc:478:20: error: expected unqualified-id before numeric constant const unsigned CHAR_WIDTH = 1;

    I think the bug has been addressed in a new version of this dependency.

    Oh, I should mention this is on GCC 6.3.1.

    bug Build 
    opened by DaulPavid 11
  • Asio's namespace

    Asio's namespace

    Currently, I'm trying to add rpclib to hunter package manager: Add rpclib to hunter-packages

    This pull request looks not okay for me. Is namespace renaming really needed? Why we can't just write this code inside rpclib's header file (we DON'T need to modify dependencies)?:

    namespace clmdep_asio
    	using namespace asio;

    rpclib will be forked to hunter-packages, because hunter somehow must manage dependencies by itself (no need in "dependency" folder)

    opened by NukeBird 9
  • Request: Add optional timeout to blocking calls

    Request: Add optional timeout to blocking calls

    I see that making a blocking call to a function when the server is not running will block forever.

    rpc::client rpc_client{port, addr};
    rpc_client.get_connection_state(); // returns "initial"
    rpc_client.call("echo", "arguments"); // hangs if the server isn't running

    This is because the future.wait() of a blocking call will wait forever. Would you accept a PR adding the ability to set a timeout? If so, what would your preferred response to an error be? Throwing an rpc_error with the what indicating timeout?

    opened by dkozel 9
  • This is not yet a pull request: Backport the codebase to C++11

    This is not yet a pull request: Backport the codebase to C++11

    • Replaces chrono_literals with std::chrono::milliseconds()
    • Define make_unique if not available
    • Replace index_sequence with manual indexing of tuple elements (limits to 5 args per call on C++11)
    • Replace decltype(auto) function types with C++11-compatible notation
    • Replace named captures in lambdas with regular captures
    • Replaced decay_t with decay<>::type
    opened by mbr0wn 8
  • Resolve multithread crash (#175)

    Resolve multithread crash (#175)

    Hi, the main goal of this PR is to solve issue #175. Here is the description of what each commit does:

    a0e6123 : Add a unit test reproducting issue #175 b18569a : fix thread safety in session management 8a98779 : Prevent the server_session to be destroyed while its closing code is still queued, causing a segfault b134678 : Fixed socket double close. If (exit_) is true, then the session is already closed and the socket_.close() is queued

    We use your library actively, please give me a feedback on this PR so it could be accepted in the official repository. It would be beneficial for everyone to avoid another fork.

    opened by qchateau 7
  • Unable to build rpclib for android

    Unable to build rpclib for android

    Hello rpclib team, How can I build rpclib for Android ? I am following this: https://kvurd.com/blog/compiling-a-cpp-library-for-android-with-android-studio/ But, where should I make changes in rpclib CMakeLists.txt ?


    opened by vaasudEva 7
  • rpclib leaks and crashes after ~1000 consecutive connections to an rpclib server

    rpclib leaks and crashes after ~1000 consecutive connections to an rpclib server


    a simple rpclib server will eventially crash after ~1000 consecutive connections. Looks like the server doesn't properly release the connection to a client after client goes out of scope. How would I properly close the client?

    test_leak crashes, test_no_leak doesn't crash.

    void test_leak(){
      for(int counter=0; ; counter++){
        rpc::client client(host, port);
        auto response = client.call("fun", "arg").as<string>();
    void test_no_leak(){
       rpc::client client(host, port);
       for(int counter=0; ; counter++){
         auto response = client.call("fun", "arg").as<string>();
    • ls -l /proc/$pid/fd | wc -l keeps increasing
    • htop shows memory keeps increasing
    • lsof -p $pid keeps increasing, showing entries such as:
    binary $pid user  ...     IPv4 ...      0t0      TCP localhost:18700->localhost:39692 (ESTABLISHED)

    EDIT: for the server, use this for eg:bind("fun", []() { return ""; });

    opened by timotheecour 7
  • rpc::server segfaults when the client unexpectedly dies

    rpc::server segfaults when the client unexpectedly dies

    Here's where it crashes:


    When server_session tries to execute write_strand_.post with the lambda it just segfaults. Here are the last three logs before the segfault happens:

    2017-11-17 06:29:38.176  DEBUG   dispatcher      Dispatching call to 'Recognize' (/tmp/rpclib-2.2.0/lib/rpc/dispatcher.cc:44)
    2017-11-17 06:29:38.219  INFO    session         Client disconnected
    2017-11-17 06:29:38.219  INFO    session         Closing session.

    I'm sorry I don't have an example which could be used to reproduce the bug.

    opened by klemen-forstneric 6
  • RPC Call Fails on large input calls

    RPC Call Fails on large input calls

    When a very large string (80k bytes) to the echo example, the client only displays the first 4102.

    To reproduce:

    compile the echo_client and echo_server example and input a ridiculously large string. Only a subset of the string will be output.

    opened by bowerscd 6
  • How to use without the server?

    How to use without the server?


    How to use without the server?

    I want transfer the data to rpclib thought a string, like you receive from server, but i will put it manually.

    I need communicate from my mobile app without the server, so i will send from mobile a string, receive on cxx side, send to rpclib and rpclib will work like it receive from http server.

    How can i do this?


    opened by paulocoutinhox 0
  • C# msgpack RPC server compatible library

    C# msgpack RPC server compatible library


    thanks for the great work. I ran both the client and the server examples successfully.

    however, I need many more features for my server-side so I can't use c++ on my server. I need c# .net core. on the other hand, I couldn't find any compatible library for .net that supports msgpack RPC

    my client is c++ and my server is C# .net core

    any recommendation? #272 #263

    opened by danyhm 0
  • Access to remote_endpoint information inside bound functor

    Access to remote_endpoint information inside bound functor

    In my case I need the address/port of the remote endpoint (client) for connection tracking purposes.

    I noticed the underlying server::impl logs the address obtained from the socket_.remote_endpoint().

    Is there any way of accessing this information inside a functor?

    Thanks in advance. LL

    opened by lflobo 0
  • v2.3.0(Jun 10, 2021)


    • Fix compile error on gcc 4.9
    • Fix warnings in clang 7
    • Fix self-assignment
    • Fix early destruction of server sessions
    • Fix crashes in multithreaded environment (#175)


    • Support calling rpc::this_server().stop() from a server procedure (#187)
    • Make rpclib compatible with codebases that do not use exceptions
    • Add server::port() to query the port used by the server
    • Set reuseaddress option on the server
    Source code(tar.gz)
    Source code(zip)
  • v2.2.1(Oct 28, 2017)


    This release fixed a crash on Windows.


    • Fixed client crashing when suppress_exceptions was on and the server threw an exception.
    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Oct 26, 2017)

    This release fixed a number of long-standing issues.


    • Fixed macOS build (#142)
    • Updated msgpack (#152)
    • Fixed a bug where the server could crash if the client timed out (#153)
    • Fixed code coverage (moved away from coveralls.io)


    • Simplified and modularized CMake script (#94)
    • Added this_session()->id() which is a unique, per-session id
    • Added waffle.io badge
    • Added missing client::clear_timeout function
    Source code(tar.gz)
    Source code(zip)
  • v2.1.1(Jul 15, 2017)

  • v2.1.0(Jul 15, 2017)

    This is mainly a bugfix release.

    Released on 2017-07-15.

    Changes since 2.0.1:

    • Fixed an issue where the server did not properly release closed connections (#125)
    • Fixed issues related to timeouts (#114, #115, #116)
    • There is no longer a default timeout
    • Fixed warnings when compiling with clang
    • Fixed the dispatcher silently accepting multiple functions with the same name (#128)
    • Changed minimum support g++ version to 4.8 from 4.9 (thanks to reddit user attomsk for letting me know)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.1(Apr 18, 2017)

    This is minor release that does not affect the library itself, just the version number constants that were forgot in 2.0.0. The documentation has some minor updates and a huge change in looks.

    Released on 2017-04-19.

    Changes since 2.0.0:

    • Bumped version number
    • Updated documentation looks
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Apr 2, 2017)

    This is an interface-breaking release (hence the major version number increase).

    Released on 2017-04-02.

    Changes since 1.0.0:

    • Added C++11 compatibility (huge thanks to Github user mbr0wn!)
    • Added global timeout for blocking calls in the client
    • Replaced the internal pimpl_ptr with std::unique_ptr for better stability
    • Fixed a build problem with newer clang versions
    • Contains some preliminary VS2013 work (but it's very far from ready)
    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Mar 10, 2017)

    This is the first, complete release of rpclib.

    Released on 2017-03-10.

    Changes since 1.0.0-preview:

    • A buffer overflow bug was fixed in the server
    • New unit tests were added
    • CMake no longer assumes libc++ when clang is used
    • Documentation fixes
    • Added the ability to pass extra flags to the build without changing the CMakeLists.txt
    • Fixed requiring RPCLIB_MSGPACK macro when not using Findrpclib.cmake
    • Created conan package
    • A benchmark suite was implemented
    Source code(tar.gz)
    Source code(zip)
Groupware server backend with RPC/HTTP, MAPI/HTTP, IMAP, POP3 and PHP-MAPI support

Gromox is the central groupware server component of grammm. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Connecti

grammm 139 Dec 26, 2022
Cap'n Proto serialization/RPC system - core tools and C++ library

Cap'n Proto is an insanely fast data interchange format and capability-based RPC system. Think JSON, except binary. Or think Protocol Buffers, except

Cap'n Proto 9.5k Dec 30, 2022
Comprehensive RPC framework with support for C++, C#, Java, JavaScript, Python and more.

Ice - Comprehensive RPC Framework Ice helps you network your software with minimal effort. By taking care of all interactions with low-level network p

ZeroC Ice 1.9k Jan 7, 2023
C++ framework for json-rpc (json remote procedure call)

I am currently working on a new C++17 implementation -> json-rpc-cxx. Master Develop | libjson-rpc-cpp This framework provides cross platform JSON-RPC

Peter Spiess-Knafl 833 Jan 7, 2023
a simple RPC wrapper generator to C/C++ functions

This project initiated from the following practical problem. To control experimental equipment via computers, manufactures provide software drivers wi

Pearu Peterson 33 Jan 8, 2023
c++11, high performance, cross platform, easy to use rpc framework.

modern C++(C++11), simple, easy to use rpc framework

qicosmos 1.2k Dec 30, 2022
nanomsg library

Welcome to nanomsg The nanomsg library is a simple high-performance implementation of several "scalability protocols". These scalability protocols are

nanomsg 5.6k Dec 30, 2022
In-progress multi-PC remote management and administration software

Volition is software to administrate, configure, and monitor vast amounts of PCs simultaneously. The end goal is to create something significantly easier to use and more flexible than Puppet or Ansible, while allowing a single command to perform a similar action on thousands of nodes running vastly different operating systems.

null 5 May 9, 2022
Packio - An asynchronous msgpack-RPC and JSON-RPC library built on top of Boost.Asio.

Header-only | JSON-RPC | msgpack-RPC | asio | coroutines This library requires C++17 and is designed as an extension to boost.asio. It will let you bu

Quentin Chateau 58 Dec 26, 2022
Industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances and thousands kinds of services. "brpc" means "better RPC".

中文版 An industrial-grade RPC framework used throughout Baidu, with 1,000,000+ instances(not counting clients) and thousands kinds of services. "brpc" m

The Apache Software Foundation 14.2k Dec 27, 2022
RPC++ is a tool for Discord RPC (Rich Presence) to let your friends know about your Linux system

RPC++ RPC++ is a tool for Discord RPC (Rich Presence) to let your friends know about your Linux system Installing requirements Arch based systems pacm

grialion 4 Jul 6, 2022
web server & client. Fully C++/WebAssembly. Server runs on google cloud function. Client uses a C++ virtual dom.

Starter project. A web server and client fully made with C++/WebAssembly. A simple CMake configuration describes how to build and run everything.

null 3 Aug 6, 2021
Socket and Networking Library using msgpack.org[C++11]

netLink C++ 11 KISS principle networking library. Features: C++ 11 IPv4, IPv6 Protocols: TCP, UDP Enable/Disable blocking mode Join/Leave UDP-Multicas

Alexander Meißner 210 Oct 18, 2022
Msgpack11 - A tiny MessagePack library for C++11 (msgpack.org[C++11])

What is msgpack11 ? msgpack11 is a tiny MsgPack library for C++11, providing MsgPack parsing and serialization. This library is inspired by json11. Th

Masahiro Wada 100 Dec 1, 2022
BingBing 60 Dec 15, 2022
MessagePack implementation for C and C++ / msgpack.org[C/C++]

msgpack for C/C++ It's like JSON but smaller and faster. Overview MessagePack is an efficient binary serialization format, which lets you exchange dat

MessagePack 2.6k Dec 31, 2022
An implementation of the MessagePack serialization format in C / msgpack.org[C]

CMP CMP is a C implementation of the MessagePack serialization format. It currently implements version 5 of the MessagePack Spec. CMP's goal is to be

Charlie Gunyon 290 Dec 31, 2022
MPack - A C encoder/decoder for the MessagePack serialization format / msgpack.org[C]

Introduction MPack is a C implementation of an encoder and decoder for the MessagePack serialization format. It is: Simple and easy to use Secure agai

Nicholas Fraser 419 Jan 1, 2023
Groupware server backend with RPC/HTTP, MAPI/HTTP, IMAP, POP3 and PHP-MAPI support

Gromox is the central groupware server component of grammm. It is capable of serving as a replacement for Microsoft Exchange and compatibles. Connecti

grammm 139 Dec 26, 2022