在C#中使用ZMQ和MacOsX

Using ZMQ in C # and Mac Os X

我想在 Mac OSX 上实现 ICP,所以我通过谷歌搜索了解了 ZeroMQ。 我使用 brew install zmq 命令安装了 ZeroMQ 但是MacOSX上关于ZeroMq的资料很少,所以我遇到了一些问题。

这是上传到 ZeroMQ 主页的示例。

public static void HWClient(string[] args)
{

using (var context = new ZContext())
using (var requester = new ZSocket(context, ZSocketType.REQ))
{
    // Connect
    requester.Connect("tcp://127.0.0.1:5555");

    for (int n = 0; n < 10; ++n)
    {
        string requestText = "Hello";
        Console.Write("Sending {0}...", requestText);

        // Send
        requester.Send(new ZFrame(requestText));

        // Receive
        using (ZFrame reply = requester.ReceiveFrame()) 
        {
            Console.WriteLine(" Received: {0} {1}!", requestText, reply.ReadString());
        }
    }
}
}

当我运行这些代码时,我会得到一个异常The type initializer for 'ZeroMQ.lib.zmq' threw an exception. 修复异常的方法很多,但是MacOSX.

中没有解决方法

请帮帮我...

我会 post 作为评论,但没有代表:

您是否尝试过使用 NetMQ (https://github.com/zeromq/netmq)?我没有在 OSX(仅 Windows)上使用它,但它是 ZMQ 的原生 C# 实现,我发现它设计得非常好,而且在我看来可能更容易上手比你正在使用的,我假设它是 C 库的 C# 包装器。

此外,如果您需要有关您正在使用的特定库的帮助,您可能应该 post 您已经尝试过哪些方法来修复异常,因为您声明有 "many ways to fix the exception, but there is no solution in Mac OSX".

我发现 https://github.com/zeromq/clrzmq4 works under MacOS X only under very special circumstances, due to several issues related to loading the native libzmq library. This is fixed to some degree in the master. There is now CI under MacOS X, so you can have a look at the CI script under https://github.com/zeromq/clrzmq4/blob/master/build.sh 的发布版本有一种安装和构建的方法。