HaiYangLib / buttonrpc

Tiny and simple c++ rpc library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

buttonrpc - a simple rpc framework for C++

Features

  • 轻量级,跨平台,简单易用
  • 服务端可以绑定自由函数,类成员函数,std::function对象
  • 服务端可以绑定参数是任意自定义类型的函数
  • 客户端与服务端自动重连机制
  • 客户端调用超时选项

Example

server:

#include "buttonrpc.hpp"

int foo(int age, int mm){
	return age + mm;
}

int main()
{
	buttonrpc server;
	server.as_server(5555);

	server.bind("foo", foo);
	server.run();

	return 0;
}

client:

#include <iostream>
#include "buttonrpc.hpp"

int main()
{
	buttonrpc client;
	client.as_client("127.0.0.1", 5555);
	int a = client.call<int>("foo", 2, 3).val();
	std::cout << "call foo result: " << a << std::endl;
	system("pause");
	return 0;
}

// output: call foo result: 5

Dependences

Building

  • vs2010 或者更高版本 (为了兼容vs2010没有用到可变模板参数)
  • gcc/g++ 支持部分c++11特性即可

Usage

About

Tiny and simple c++ rpc library


Languages

Language:C++ 78.3%Language:C 21.7%