简体   繁体   English

如何将数据从C#推送到ZeroMQ并从Node.JS提取,反之亦然?

[英]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.

相关问题 从Java运行C#代码,反之亦然 - Run C# code from Java and vice-versa c# - 可以从C#类型转换为System.Type但反之亦然 - c# - can convert from C# type to System.Type but not vice-versa 从我的网站到 .NET (C#) 进行通信的正确方法是什么,反之亦然? - What is a proper way to communicate from my website to the .NET (C#) and vice-versa? 尝试从另一个文本框更新一个文本框,反之亦然C#Winforms - Trying to update one textbox from another and vice-versa C# Winforms Visual Studio C# 项目在从调试切换到发布时强制重建,反之亦然 - Visual Studio C# projects force a rebuild when switching from debug to release and vice-versa 如何使用BluetoothDeviceInfo中的信息识别HID设备,反之亦然 - How to identify HID Device with information from BluetoothDeviceInfo or vice-versa 从arduino接收数据并将数据发送到C#,反之亦然 - Receive and send data from arduino to c# and vice versa 在C#中将字符串数组转换为简单字符串,反之亦然 - converting an array of strings into a simple string and vice-versa in c# C#字节数组为字符串,反之亦然 - C# byte array to string, and vice-versa 在z#中将zenkaku字符转换为hankaku,反之亦然 - Converting zenkaku characters to hankaku and vice-versa in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM