All Projects → xoofx → SharpNng

xoofx / SharpNng

Licence: BSD-2-Clause License
SharpNng is a lightweight low-level managed wrapper around the Lightweight Messaging Library NNG

Programming Languages

C#
18002 projects
powershell
5483 projects
CMake
9771 projects

Projects that are alternatives of or similar to SharpNng

runng
No description or website provided.
Stars: ✭ 23 (-17.86%)
Mutual labels:  nanomsg, nng
nanomsg-browser
nanomsg websocket connection for the browser
Stars: ✭ 26 (-7.14%)
Mutual labels:  nanomsg
Nanomsg.swift
Swift binding for nanomsg
Stars: ✭ 15 (-46.43%)
Mutual labels:  nanomsg
d-nanomsg
experimental d-lang bindings for nano msg
Stars: ✭ 14 (-50%)
Mutual labels:  nanomsg
pink-0
Ableton Link to clock/reset signals converter
Stars: ✭ 87 (+210.71%)
Mutual labels:  nanomsg
Mangos V1
The pure golang implementation of nanomsg (version 1, frozen)
Stars: ✭ 1,533 (+5375%)
Mutual labels:  nanomsg

SharpNng Build Status Build Status NuGet

SharpNng is a lightweight low-level managed wrapper around NNG a Lightweight Messaging Library.

The current native version of NNG used by SharpNng is 1.5.2

Features

  • Strict mapping with the C API
  • Pure DllImport library via using static nng;
  • Compatible with netstandard2.0 and netstandard2.1+
  • Fast interop with Span friendly API.

Usage

  • Install the SharpNng NuGet Package to your project.
using static nng;
 // port of https://nanomsg.org/gettingstarted/nng/reqrep.html
string ipcName = $"ipc:///tmp/SharpNng_{Guid.NewGuid():N}.ipc";

var sync = new EventWaitHandle(false, EventResetMode.ManualReset);

void Node0()
{
    nng_socket sock = default;

    int result = nng_rep0_open(ref sock);
    nng_assert(result);
    try
    {
        nng_listener listener = default;
        result = nng_listen(sock, ipcName, ref listener, 0);
        nng_assert(result);

        IntPtr buf;
        size_t sz = default;

        TestContext.Out.WriteLine("Server: Listening");

        sync.Set();

        unsafe
        {
            result = nng_recv(sock, new IntPtr(&buf), ref sz, NNG_FLAG_ALLOC);
            nng_assert(result);
        }

        Assert.AreEqual(4, sz.Value.ToInt64());

        nng_free(buf, sz);
    }
    finally
    {
        result = nng_close(sock);
    }
};

void Node1()
{
    TestContext.Out.WriteLine("Client: Started");

    nng_socket sock = default;

    int result = nng_req0_open(ref sock);
    nng_assert(result);

    try
    {
        nng_dialer dialer = default;
        result = nng_dial(sock, ipcName, ref dialer, 0);
        nng_assert(result);

        TestContext.Out.WriteLine("Client: Connected");

        unsafe
        {
            int value = 0x6afedead;
            result = nng_send(sock, new IntPtr(&value), 4, 0);
            nng_assert(result);
        }
    }
    finally
    {
        result = nng_close(sock);
    }
};

// Start the server
var thread = new Thread(Node0)
{
    IsBackground = true
};
thread.Start();

// Wait for the server to start
sync.WaitOne(1000);

// Run the client
Node1();

Platforms

SharpNng is supported on the following platforms:

  • win-x64, win-x86, win-arm64, win-arm
  • linux-x64, linux-arm64, linux-arm
  • osx-x64, osx-arm64

Note that the Linux version might probably only work on debian derivatives for now...

How to Build?

You need to install the .NET 6 SDK. Then from the root folder:

$ dotnet build src -c Release

In order to rebuild the native binaries, you need to run the build scripts from ext

License

This software is released under the BSD-Clause 2 license.

Author

Alexandre Mutel aka xoofx.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].