[nanomsg] .NET, simple test

  • From: Sierwald, Jörn <Joern.Sierwald@xxxxxxxxxxxxx>
  • To: "nanomsg@xxxxxxxxxxxxx" <nanomsg@xxxxxxxxxxxxx>
  • Date: Thu, 8 Feb 2018 16:30:28 +0000

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: