C# ØMQ Server Client Example, C# ZeroMQ Sender Receiver Pair

C# ØMQ Server Client Example, C# ZeroMQ Sender Receiver Pair

First, download source files from ZeroMq .Net Download Page and build the project in src\ZeroMQ for Windows to produce required library and dll files. Then:

1. Open a new project.

2. Add clrzmq.dll you produce to your project references.

3. Copy libzmq.dll to your build directory.

4. Build and run your first .NET ØMQ applications.

C# ØMQ Receiver Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZeroMQ;

namespace ZeroMqNetReceiver
{
    class Receiver
    {
        static void Main(string[] args)
        {
            using (var context = ZmqContext.Create())
            using (var socket =
                        context.CreateSocket(SocketType.PAIR))
            {
                socket.Bind("tcp://*:5555");

                Console.WriteLine("NET Receiver: Started");

                while (true)
                {
                    Frame request = socket.ReceiveFrame();
                    String message = Encoding.UTF8.GetString(request);
                    Console.WriteLine("NET Receiver: Received (" + message + ")");
                }
            }
        }
    }
}

C# ØMQ Sender Code

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using ZeroMQ;

namespace ZeroMqNetSender
{
    class Sender
    {
        static void Main(string[] args)
        {
            using (var context = ZmqContext.Create())
            using (var socket = context.CreateSocket(SocketType.PAIR))
            {
                socket.Connect("tcp://localhost:5555");

                Console.WriteLine("NET Sender: Started");

                for (int i = 0; i < 10; ++i )
                {
                    Thread.Sleep(1000);

                    String message = "NET Message " + (i + 1);
                    Console.WriteLine("NET Sender: Sending (" + message + ")");
                    socket.SendFrame(new Frame(Encoding.UTF8.GetBytes(message)));
                }
            }
        }
    }
}

Download .NET ZeroMQ Sender and Receiver and try running the application for windows operating systems.


C# ØMQ Server Client Example, C# ZeroMQ Sender Receiver Pair
added 10 years 8 months ago

Contents related to 'C# ØMQ Server Client Example, C# ZeroMQ Sender Receiver Pair'

C/C++ ØMQ Server Client Example, ZeroMQ Sender Receiver Pair: Example C/C++ zeromq sender receiver source code, C ØMQ server client model source code examples.

Coordinating C/C++ ØMQ and .NET ØMQ: This page gives source code examples of C/C++ ØMQ and .NET ØMQ that can run in conjunction.

- C# Parse Tree
- How to create xml document in C#
- C# ØMQ Server Client Example, C# ZeroMQ Sender Receiver Pair
- C/C++ ØMQ Server Client Example, ZeroMQ Sender Receiver Pair