A collection of Fortran 2018 ISO C binding interfaces to the lightweight messaging library NNG v1.11.0:
NNG, like its predecessors nanomsg (and to some extent ZeroMQ), is a lightweight, broker-less library, offering a simple API to solve common recurring messaging problems, such as publish/subscribe, RPC-style request/reply, or service discovery. The API frees the programmer from worrying about details like connection management, retries, and other common considerations, so that they can focus on the application instead of the plumbing.
The bindings cover the API of NNG v1 (stable). See branch
v2 for bindings to NNG v2.
Link your Fortran programs with libfortran-nng.a and libnng.so. If
fortran-nng is installed to /opt, run:
$ gfortran -I/opt/include/libfortran-nng -o example example.f90 /opt/lib/libfortran-nng.a -lnng
For Fortran bindings to nanomsg, see nanofort.
On Linux, install NNG with development headers first:
$ sudo apt-get install libnng1 libnng-dev nng-utils
On FreeBSD:
$ doas pkg install net/nng
Alternatively, build NNG simply from source and install it to /opt:
$ git clone --depth 1 --branch v1.11 https://github.com/nanomsg/nng.git
$ mkdir -p nng/build && cd nng/build/
$ cmake -DCMAKE_INSTALL_PREFIX:PATH=/opt ..
$ make
$ make install
If the NNG library is installed globally, build and install the interfaces library with GNU Fortran by running:
$ make
If you prefer LLVM, run, for example:
$ make CC=clang21 FC=flang21
If the NNG library is installed in /opt, pass the prefix:
$ make PREFIX=/opt
To link against a static libnng.a library instead, run:
$ make LDLIBS="/path/to/libnng.a -lpthread"
Install the fortran-nng library and module files to /opt:
$ make install PREFIX=/opt
This project supports the Fortran Package Manager (FPM). To build the project with FPM, run:
$ fpm build --profile release
The example programs are available with the fpm run --example command. You
can add fortran-nng to your fpm.toml with:
[dependencies]
fortran-nng = { git = "https://github.com/interkosmos/fortran-nng.git" }The following programs can be found in directory examples/:
- async implements an asynchronous RPC service.
- bus creates an interconnected mesh network.
- http_client sends an HTTP GET request and outputs the response.
- pair shows one-to-one peer relationship.
- pipeline solves producer/consumer problem with pipeline (one-way pipe).
- pubsub shows pub/sub messaging pattern.
- pubsub_forwarder implements a simple pub/sub forwarder.
- reqrep demonstrates request-response pattern between client and server.
- survey sends a timed survey out.
Build the examples with:
$ make examples
The fortran-nng bindings differ slightly from the C API:
- Derived types do not have to be initialised like in C.
- All strings passed to the NNG interfaces have to be properly null-terminated
with constant
c_null_char, except for parameter strings already provided by the Fortran modules. You can use functionf_c_str()from modulenng_utilto add the null-termination. - C string pointers returned by NNG functions are converted to Fortran
allocatable character through wrappers. The interfaces are public and end with
suffix
_. - The prefix of
nng_log_levelenumerators has been changed fromNNG_LOG_toNNG_LOG_LEVEL_due to conflicts with procedures of the same name. - The prefix of
nng_log_facilityenumerators has been changed fromNNG_LOG_toNNG_LOG_FACILITY_due to conflicts with procedures of the same name. - The interfaces to the NNG log functions expect a single (non-variadic) string argument only.
The source code documentation has to be created with FORD. Install the Python package with:
$ python3 -m pip install -U ford
In the fortran-nng repository, run:
$ make doc
The HTML files will be written to directory doc/. Open index.html in a web
browser.
- NNG Web Site
- NNG Repository
- NNG Reference Manual
- NNG API Documentation (v1.10.0)
- Getting Started with NNG
ISC