[英]How to Push data from C# to ZeroMQ and Pull from Node.JS or vice-versa?
Scenario : 场景 :
I am trying to send a data (say String
type) from C# сonsole application to Node.JS server through ZeroMQ. 我正在尝试通过ZeroMQ将数据(例如
String
类型)从C#сonsole应用程序发送到Node.JS服务器。
Information: 信息:
Using clrzmq for c# and ZeroMQ libs for C# and Node.JS respectively 将clrzmq分别用于C#和ZeroMQ库,分别用于C#和Node.JS
I am able to perform push-pull from Node.JS, also push - pull from C#. 我能够进行推拉从Node.js的,也推 - 拉从C#。
So, one thing is confirmed that ZeroMQ - The Intelligent Transport Layer is installed on the machine (Windows 7 64-bit) 因此,一件事被确认为ZeroMQ-智能传输层已安装在计算机上(Windows 7 64位)
Issue : 问题 :
I am not able to push data from C# Console app to Node.JS app (even tried vice-versa), both are on the same machine and on the same address ie tcp://127.0.0.1:2222
我无法将数据从C#控制台应用程序推送到Node.JS应用程序(甚至尝试将其反之),两者都在同一台计算机上,并且在同一地址上,即
tcp://127.0.0.1:2222
Node.js code: Node.js代码:
var zmq = require('zeromq.node');
var pull_socket = zmq.socket('pull');
pull_socket.connect('tcp://127.0.0.1:2222');
pull_socket.on('message', function (data) {
console.log('received data:\n');
console.log(data);
});
C# code: C#代码:
namespace DataServiceEngine
{
class Program
{
static void Main(string[] args)
{
//clsApp App = new clsApp();
//App.appId = "001";
//App.name = "Back Office";
//Console.WriteLine("appId :" + App.appId + "\n");
//Console.WriteLine("name:" + App.name + "\n");
try
{
// ZMQ Context and client socket
using (var context = new Context(1))
{
using (Socket client = context.Socket(SocketType.PUSH))
{
client.Connect("tcp://127.0.0.1:2222");
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);
}
}
}
}
catch (ZMQ.Exception exp)
{
Console.WriteLine(exp.Message);
}
}
}
}
Question : Can anyone tell me what may be the reason or where am I doing wrong? 问题 :谁能告诉我原因是什么或我在哪里做错了?
I had the same issue (but I issued a communication Node.JS -> Node.JS). 我遇到了同样的问题(但是我发布了一个通信Node.JS-> Node.JS)。 To solve the problem I used to do
sendersocket.connect("tcp://"+host+":"+port);
为了解决这个问题,我曾经做过
sendersocket.connect("tcp://"+host+":"+port);
at the sender and receiversocket.bindSync("tcp://*:"+port);
在发送方和
receiversocket.bindSync("tcp://*:"+port);
方receiversocket.bindSync("tcp://*:"+port);
at the receiver. 在接收器处。
Hope this fix your problem. 希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.