C#

C#

C#

Two options are available for C# developers, NetMQ, a port of zeromq to C#, or clrzmq4, C# binding for libzmq.

NetMQ is the recommended option. However NetMQ doesn’t implement ZMTP 3 and curve encryption at the moment.

NetMQ

Githubhttps://github.com/zeromq/netmq
Docshttps://netmq.readthedocs.io/en/latest/
Nugethttps://www.nuget.org/packages/NetMQ

Request-Response

Client:

using (var client = new RequestSocket())
{
    client.Connect("tcp://127.0.0.1:5556");
    client.SendFrame("Hello");
    var msg = client.ReceiveFrameString();
    Console.WriteLine("From Server: {0}", msg);
}

Server:

using (var server = new ResponseSocket())
{
    client.Bind("tcp://*:5556");
    string msg = server.ReceiveFrameString();
    Console.WriteLine("From Client: {0}", msg);
    server.SendFrame("World");
}

Pub-Sub

Subscriber:

using (var subscriber = new SubscriberSocket())
{
    subscriber.Connect("tcp://127.0.0.1:5556");
    subscriber.Subscribe("A");

    while (true)
    {
        var topic = subscriber.ReceiveFrameString();
        var msg = subscriber.ReceiveFrameString();
        Console.WriteLine("From Publisher: {0} {1}", topic, msg);
    }
}

Publisher:

using (var publisher = new PublisherSocket())
{
    publisher.Bind("tcp://*:5556");

    int i = 0;

    while (true)
    {
        publisher
            .SendMoreFrame("A") // Topic
            .SendFrame(i.ToString()); // Message

        i++;
        Thread.Sleep(1000);
    }
}

clrzmq4

Githubhttps://github.com/zeromq/clrzmq4
Nugethttps://www.nuget.org/packages/ZeroMQ/

Package include libzmq for Windows, for OSX and Linux you need to install libzmq.

© 2019 The ZeroMQ authors