Skip to content
No description or website provided.
C# Other
  1. C# 98.9%
  2. Other 1.1%
Branch: master
Clone or download
jake-ruyi Feature/master examples (#51)
* Initial examples/nngcat/

- C# version of https://nanomsg.github.io/nng/man/v1.1.0/nngcat.1

* Mention examples/ in README
Latest commit 1bf8f07 Feb 26, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
dockerfiles Fix numerous tests (#26) Feb 2, 2019
examples/nngcat Feature/master examples (#51) Feb 26, 2019
nng.NETCore
nng.Shared
scripts
tests
.dockerignore
.gitignore
.travis.yml
LICENSE
README.md
appveyor.yml
common.targets
nng.NETCore.sln
package.json Pinvoke for majority of nng Sep 3, 2018

README.md

nng.NETCore

.NET Core bindings to NNG:

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.

Status:

Using latest NNG release.

NuGet Build status Build status codecov

For list of missing APIs/features see is:issue is:open label:enhancement.

Goals of nng.NETCore:

  • Async first: async/await access to nng_aio and nng_ctx
  • Native layer: P/Invoke in separate files/namespace. Don't like our high-level OO wrapper? Re-use the pinvoke and make your own. Also makes cross-platform-friendly pinvoke easier.
  • Tests as Documentation: xUnit unit/integration tests in "plain" C# much like you'd write
  • .NET Core friendly: Using dotnet and targetting .NET Standard from the start
  • Few surprises: Simple class heirarchy (more composition than inheritance), minimal exceptions, idiomatic C# that when reasonable is similar to original native code

Usage

Supports projects targetting:

Supported platforms:

  • Windows Vista or later 32/64-bit
  • macOS/OSX 10.?+ (built on 10.14)
  • Linux x86_64 (built on Ubuntu 18.04)
  • Linux ARM64/aarch64 (built on Debian 9/stretch)

Should be easy to add others that are supported by both .NET Core and NNG.

After installing the package and building, your output folder should have runtimes/ directory containing native binaries.

On .NET Core/Standard use NngLoadContext (or your own AssemblyLoadContext) to load the appropriate native library and use NNG:

var path = Path.GetDirectoryName(typeof(Program).Assembly.Location);
var ctx = new nng.NngLoadContext(path);
var factory = nng.NngLoadContext.Init(ctx);
// Use factory...

See tests/ and examples/ for usage examples.

Build & Run

You should be able to build nng.NETCore for/on any platform supported by .NET Core:

  1. Build: dotnet build
  2. Run: dotnet run or dotnet test tests

You should be able to build the NNG native shared library for any platform supported by NNG:

  1. Download/clone NNG source
  2. On Windows, create Command Prompt suitable for Visual Studio:
    • Run x64 Visual Studio Developer Command Prompt to create a 64-bit library (or x86 for 32-bit)
    • OR, run vcvars64.bat in cmd.exe (or vcvars32.bat)
  3. Make sure cmake and Ninja are in PATH environment variable
  4. Run:
    mkdir build && cd build
    cmake -G Ninja -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release ..
    ninja
    
  5. Copy library to appropriate nng.NETCore/runtimes/XXX/native/ directory

.NET Framework

System.Runtime.Loader is not available in .NET Framework, so the correct assembly must be loaded by some other means.

If your application is targetting .Net Framework 4.6+ and you get lots of:

message NETSDK1041: Encountered conflict between 'Reference:XXX\.nuget\packages\subor.nng.netcore\0.0.5\lib\netstandard2.0\Microsoft.Win32.Primitives.dll' and 'Reference:Microsoft.Win32.Primitives'.  NETSDK1034: Choosing 'Reference:XXX\.nuget\packages\subor.nng.netcore\0.0.5\lib\netstandard2.0\Microsoft.Win32.Primitives.dll' because file version '4.6.26419.2' is greater than '4.6.25714.1'.

<snip>

XXX\Properties\AssemblyInfo.cs(8,12,8,25): error CS0246: The type or namespace name 'AssemblyTitleAttribute' could not be found (are you missing a using directive or an assembly reference?)

Try adding the following to your project:

<PropertyGroup>
    <DependsOnNETStandard>false</DependsOnNETStandard>
</PropertyGroup>
You can’t perform that action at this time.