【问题标题】:How to install clrzmq using Package Manager Console for a console c# application?如何使用包管理器控制台为控制台 c# 应用程序安装 clrzmq?
【发布时间】:2013-03-17 13:43:32
【问题描述】:

场景:一旦 Node.js 服务器在 tcp://127.0.0.1:2202 上监听 ZeroMQ。并且数据必须由 C# 控制台应用程序发送。

问题:
Example Reference

using System;
using System.Text;
using ZMQ;

namespace ZMQGuide
{
    class Program
    {
        static void Main(string[] args)
        {
            // ZMQ Context and client socket
            using (ZmqContext context = ZmqContext.Create())
            using (ZmqSocket client = context.CreateSocket(SocketType.PUSH))
            {
                client.Connect("tcp://127.0.0.1:2202");

                string request = "Hello";
                for (int requestNum = 0; requestNum < 10; requestNum++)
                {
                    Console.WriteLine("Sending request {0}...", requestNum);
                    client.Send(request, Encoding.Unicode);

                    string reply = client.Receive(Encoding.Unicode);
                    Console.WriteLine("Received reply {0}: {1}", requestNum, reply);
                }
            }
        }
    }
}

出现以下错误:

Error   1   The type or namespace name 'ZmqContext' could not be found (are you missing a using directive or an assembly reference?)    D:\..\Program.cs    26  24  PROJECTA

信息:我尝试通过发出命令PM&gt; Install-Package clrzmq 使用包管理器控制台安装最新版本 命令后的输出:

'clrzmq 2.2.5' already installed.
Successfully added 'clrzmq 2.2.5' to PROJECTA.

问题:谁能告诉我,我哪里出错了或者我错过了什么?


更新:我有 downloaded 并尝试过,但没有运气 :-)

提前感谢您的大力帮助

【问题讨论】:

    标签: c# .net clr zeromq package-managers


    【解决方案1】:

    我可以重现您的问题。我认为这可能是因为文档有点过时,但这似乎是为我构建的:

    using ZMQ;
    
    namespace TestConsole 
    {
        class Program
        {
            static void Main(string[] args)
            {
                // ZMQ Context and client socket
                using (Context context = new Context())
                using (Socket client = context.Socket(SocketType.PUSH))
                {
                    client.Connect("tcp://127.0.0.1:2202");
    
                    string request = "Hello";
                    for (int requestNum = 0; requestNum < 10; requestNum++)
                    {
                        Console.WriteLine("Sending request {0}...", requestNum);
                        client.Send(request, Encoding.Unicode);
    
                        string reply = client.Recv(Encoding.Unicode);
                        Console.WriteLine("Received reply {0}: {1}", requestNum, reply);
                    }
                }
            }
        }
    }
    

    我没有运行 ZeroMQ 或任何东西来实际检查它是否工作,但也许你可以试一试?

    【讨论】:

    • 运气不好 :-( Error 1 The type or namespace name 'ZeroMQ' could not be found (are you missing a using directive or an assembly reference?) D:\..\Program.cs 6 7 ProjectA
    • 对此感到抱歉...我只是将包从 NuGet 拖下来并尝试运行。已经用对我有用的方法更新了我的答案(至少在构建阶段)
    • 感谢您的大力帮助.. 我得到了这个但对我来说现在问题出在服务器端(上面的代码是客户端的)。收到第一条消息时出现异常.. Unhandled Exception: ZMQ.Exception: Not supported at ZMQ.Socket.Send(Byte[] message, Int32 startIndex, Int32 length, SendRecvOpt[] flags)
    • 很高兴你成功了......对不起,我不是 ZMQ 专家,所以我希望我能提供更多帮助,但很遗憾我不能:-(
    【解决方案2】:

    根据我的经验,要获得 clrzmq (ZeroMQ) 的最新版本 (3.0),我需要在 Package Manager 调用中添加“-Version”选项,如下所示:

    下午>Install-Package clrzmq -Version 3.0.0-rc1

    另外,当使用 3.0 时,“使用”是 ZeroMQ 而不是 ZMQ:

    using ZeroMQ;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多