如何推进从C#的数据ZeroMQ和Node.js的拉动,反之亦然? [英] How to Push data from C# to ZeroMQ and Pull from Node.JS or vice-versa?
问题描述
场景
我试图发送一个数据(比如字符串
从通过ZeroMQ C#сonsole应用的Node.js服务器类型)
信息:
使用C#的clrzmq和ZeroMQ库为C#和Node.js的分别为
我能够执行的从Node.js的推拉,也的推 - 拉从C#
所以,有一件事是证实 ZeroMQ - 的智能交通层是安装在机器上(Windows 7的64位)
问题
我不能够从C#控制台应用程序数据推到的Node.js应用程序(甚至试图反之亦然),两者都在同一台机器上,并在同一个地址,即 TCP://127.0.0.1 2222
Node.js的代码:
VAR ZMQ =要求('zeromq.node');
VAR pull_socket = zmq.socket(拉);
pull_socket.connect('TCP://127.0.0.1:2222');
pull_socket.on(信息,功能(数据){
的console.log('接收到的数据:\\\
');
的console.log(数据);
});
C#代码:
命名空间DataServiceEngine
{
类节目
{
静态无效的主要(字串[] args)
{
// clsApp应用=新clsApp();
//App.appId =001;
//App.name =后台;
//Console.WriteLine(\"appId:+ App.appId +\\\
);
//Console.WriteLine(\"name:+ App.name +\\\
);
试
{
// ZMQ上下文和客户端套接字
使用(VAR上下文=新的上下文(1))
{
使用(客户端的Socket = context.Socket(SocketType.PUSH))
{
client.Connect(TCP://127.0.0.1:2222);
串请求=你好;
为(INT requestNum = 0; requestNum小于10; requestNum ++)
{
Console.WriteLine(发送请求{0} ...,requestNum);
client.Send(请求Encoding.Unicode);
串答复= client.Recv(Encoding.Unicode);
Console.WriteLine(收到回复{0}:{1},requestNum,回复)
}
}
}
}
赶上(ZMQ.Exception EXP)
{
Console.WriteLine(exp.Message);
}
}
}
}
< STRONG>问题:谁能告诉我可能是什么原因,或者我做错了。
我?有同样的问题(但我发出了通信的Node.js - > Node.js的)。为了解决我以前做的 sendersocket.connect问题(TCP://+主机+:+端口);
在发送者和 receiversocket.bindSync(TCP:// *+端口);
在接收器
希望这会解决您的问题。 p>
Scenario:
I am trying to send a data (say String
type) from C# сonsole application to Node.JS server through ZeroMQ.
Information:
Using clrzmq for c# and ZeroMQ libs for C# and Node.JS respectively
I am able to perform push-pull from Node.JS, also push - pull from C#.
So, one thing is confirmed that ZeroMQ - The Intelligent Transport Layer is installed on the machine (Windows 7 64-bit)
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 i.e tcp://127.0.0.1:2222
Node.js code:
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:
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). To solve the problem I used to do sendersocket.connect("tcp://"+host+":"+port);
at the sender and receiversocket.bindSync("tcp://*:"+port);
at the receiver.
Hope this fix your problem.
这篇关于如何推进从C#的数据ZeroMQ和Node.js的拉动,反之亦然?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!