Now the newest version is in topling-ark
RPC(Remote Procedure Call) on top of nark-serialization
boost-1.41 or newer |
|
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
boost_thread
,boost_date_time
,boost_system
- 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!
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()
- Function overload is not allowed in IDL.
RPC_DECLARE_MF
orRPC_DECLARE_MF_D
should be used consitently in the same RPC interface.
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
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
To be written...