mesytec-mnode/external/nng/demo/reqrep
2024-12-28 04:48:21 +01:00
..
CMakeLists.txt Merge commit 'b6a2ffe5d052d79b3e6f9be239111f0d594b41cb' as 'external/nng' 2024-12-28 04:48:21 +01:00
README.adoc Merge commit 'b6a2ffe5d052d79b3e6f9be239111f0d594b41cb' as 'external/nng' 2024-12-28 04:48:21 +01:00
reqrep.c Merge commit 'b6a2ffe5d052d79b3e6f9be239111f0d594b41cb' as 'external/nng' 2024-12-28 04:48:21 +01:00

= reqrep

This is a very simple RPC service using the REQ/REP method.
It is derived in part from Tim Dysinger's
http://nanomsg.org/gettingstarted/[Getting Started With Nanomsg]
examples, but we have updated for _nng_, and converted to use binary
frames across the wire instead of string data.

The protocol is simple:

* Client will send a 64-bit command (network byte order, i.e. big endian).
* Server sends a 64-bit response (also network byte order.)

The only command is "DATE", which has value 0x1.  The value returned is
a UNIX timestamp (seconds since Jan 1, 1970.)

(We used 64-bit values for simplicity, and to avoid the Y2038 bug when
compiled on 64-bit systems.)

== Compiling

CMake with ninja-build is simplest:

[source, bash]
----
% mkdir build
% cd build
% cmake -G Ninja ..
% ninja
----

Or if you prefer a traditional approach, 
the following is an example typical of UNIX and similar systems like
Linux and macOS may appeal:

[source, bash]
----
% export CPPFLAGS="-I /usr/local/include"
% export LDFLAGS="-L /usr/local/lib -lnng"
% export CC="cc"
% ${CC} ${CPPFLAGS} reqrep.c -o reqrep ${LDFLAGS}
----

== Running

You can run either the client or the server, and use whatever legal
_nng_ URL you like:

[source, bash]
----
% ./reqrep server tcp://127.0.0.1:8899 &
% ./reqrep client tcp://127.0.0.1:8899
CLIENT: SENDING DATE REQUEST
SERVER: RECEIVED DATE REQUEST
SERVER: SENDING DATE: Thu Feb  8 10:26:18 2018
CLIENT: RECEIVED DATE: Thu Feb  8 10:26:18 2018
----