Skip to content

rockeet/nark-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published