[nanomsg] Re: .NET, simple test

  • From: "Garrett D'Amore" <garrett@xxxxxxxxxx>
  • To: nanomsg@xxxxxxxxxxxxx
  • Date: Thu, 08 Feb 2018 17:04:08 +0000

Awesome!  I remain somewhat ambivalent about .NET in general, but I’m glad
that nng works in other runtimes — that is actually a design goal!

 - Garrett

On Thu, Feb 8, 2018 at 8:30 AM Sierwald, Jörn <Joern.Sierwald@xxxxxxxxxxxxx>
wrote:

Good afternoon,



You might be delighted or horrified to know that nng 0.2.0 works just fine
in .NET. I took the static library and turned it into a .NET assembly using
C++/CLI. I just wrapped the most important functions, modified only the
parameters.

If somebody here did something similar, got further or got into trouble
please respond.

Looking forward to playing with 0.5.0.



Jörn





        static void node0()

        {

            NngSocket socket;

            NngListener listener;

            Nng.nng_rep0_open(out socket);

            Nng.nng_listen(socket, "ipc:///myfirstpipe", out listener, 0);

            byte[] data;

            Nng.nng_recv(socket, out data, 0);

            foreach (var i in data) { System.Console.WriteLine(i); }

            data = new byte[] { 4, 5, 6 };

            Nng.nng_send(socket, data, 0);

            Nng.nng_close(socket);

        }

        static void node1()

        {

            NngSocket socket;

            NngDialer dialer;

            Nng.nng_req0_open(out socket);

            Nng.nng_dial(socket, "ipc:///myfirstpipe", out dialer, 0);

            Nng.nng_send(socket, new byte[] { 1, 2, 3 }, 0);

            byte[] data;

            Nng.nng_recv(socket, out data, 0);

            foreach (var i in data) { System.Console.WriteLine(i); }

            Nng.nng_close(socket);



        }



        static void Main(string[] args)

        {



            System.Threading.Thread thread0 = new
System.Threading.Thread(node0);

            thread0.Start();

            System.Threading.Thread.Sleep(1000);

            node1();

       }

Other related posts: