场景:一旦Node.js服务器在tcp://127.0.0.1:2202
上进行了ZeroMQ拉取监听。数据必须由C#控制台应用程序发送。
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
信息:我尝试使用Package Manager控制台安装最新版本,发出命令PM> Install-Package clrzmq
命令后输出:
'clrzmq 2.2.5' already installed.
Successfully added 'clrzmq 2.2.5' to PROJECTA.
问题:有谁能告诉我,我哪里出错或者我错过了什么?
<小时/> 更新:我有downloaded并试过,但没有运气: - )
预先感谢您的大力帮助
答案 0 :(得分:3)
我可以重现你的问题。我想这也许是因为文档有点过时了,但这似乎适合我:
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或其他任何运行实际检查它是否有效,但也许你可以试一试?
答案 1 :(得分:2)
根据我的经验,要获得clrzmq(ZeroMQ)的最新版本(3.0),我需要将“-Version”选项添加到Package Manager调用中,如下所示:
PM&GT; Install-Package clrzmq -Version 3.0.0-rc1
此外,使用3.0时,“使用”是ZeroMQ而不是ZMQ:
using ZeroMQ;