Giter Site home page Giter Site logo

skyformat99 / nark-rpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rockeet/nark-rpc

0.0 3.0 0.0 105 KB

RPC(Remote Procedure Call) on top of nark-serialization

License: GNU Affero General Public License v3.0

Makefile 7.68% Shell 3.24% C++ 89.08%

nark-rpc's Introduction

nark-rpc

RPC(Remote Procedure Call) on top of nark-serialization

Prerequisite

boost-1.41 or newer
  • Require `boost_thread`, `boost_date_time`, `boost_system` to be built
  • Other boost libraries are used as header-only
nark-serialization Require binary library
nark-hashmap header only
nark-bone Require binary library

Note: All nark repositories should be in the same directory.

Compile

  1. Compile boost_thread, boost_date_time, boost_system
  2. Compile
$ cd /path/to/nark-bone
$ make
$ cd ../nark-serialization
$ make
$ cd ../nark-rpc
$ make
$ cd samples # /path/to/nark-rpc/samples
$ make
$ build/*/dbg/echo_server/echo_server.exe # run echo server
$ #
$ # open a new terminal
$ build/*/dbg/echo_client/echo_client.exe # run echo client
$ # Have Fun!

Quick Start

IDL

nark-rpc are all in C++, even its IDL is C++, samples/ifile.h is a good example:

BEGIN_RPC_INTERFACE(FileObj, SessionScope)
    RPC_ADD_MF(open)
    RPC_ADD_MF(read)
    RPC_ADD_MF(write)
    RPC_ADD_MF(close)
END_RPC_ADD_MF()
    RPC_DECLARE_MF(open, (const string& fname, const string& mode))
    RPC_DECLARE_MF(read, (vector<char>* buffer, uint32_t length))
    RPC_DECLARE_MF(write, (const vector<char>& buffer, uint32_t* length))
    RPC_DECLARE_MF(close, ())
END_RPC_INTERFACE()

This can be thought of as nark-rpc's IDL, as it declared, FileObj is in SessionScope.

There is another scope: GlobaleScope, samples/echo.h is such an example:

BEGIN_RPC_INTERFACE(Echo, GlobaleScope)
    RPC_ADD_MF(echo)
END_RPC_ADD_MF()
    RPC_DECLARE_MF_D(echo, (const string& msg, string* echoFromServer))
END_RPC_INTERFACE()

Notes

  1. Function overload is not allowed in IDL.
  2. RPC_DECLARE_MF or RPC_DECLARE_MF_D should be used consitently in the same RPC interface.

Client

RPC client just call the (member) functions defined in IDL, the functions seem defined as normal functions. RPC_DECLARE_MF and RPC_DECLARE_MF_D are the same at client side.

See samples/file_client/file_client.cpp
See samples/echo_client/echo_client.cpp

Server

RPC server implement the (member) functions, these functions are called by the client through network.

Writing a RPC server is as simple as writing a normal class:

Functions declared by RPC_DECLARE_MF are pure virtual, so you must define an implementation class:
See samples/file_server/file_server.cpp

Functions declared by RPC_DECLARE_MF_D are not pure virtual, _D means Direct:
See samples/echo_server/echo_server.cpp

More

To be written...

nark-rpc's People

Contributors

rockeet avatar

Watchers

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