【问题标题】:How to Push data from C# to ZeroMQ and Pull from Node.JS or vice-versa?如何将数据从 C# 推送到 ZeroMQ 并从 Node.JS 拉取数据,反之亦然?
【发布时间】:2013-03-28 07:48:58
【问题描述】:

场景

我正在尝试通过 ZeroMQ 从 C# сonsole 应用程序向 Node.JS 服务器发送数据(比如 String 类型)。

信息:

分别将 clrzmq 用于 c# 和 ZeroMQ 库用于 C# 和 Node.JS

我可以从 Node.JS 执行 push-pull,也可以从 C# 执行 push - pull

所以,确认一件事是在机器上安装了ZeroMQ - The Intelligent Transport Layer(Windows 7 64-bit)

问题

我无法将数据从 C# 控制台应用程序推送到 Node.JS 应用程序(甚至尝试过反之亦然),两者都在同一台机器和同一地址上,即 tcp://127.0.0.1:2222

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#代码:

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);
            }
        }
    }
}

问题:谁能告诉我可能是什么原因或我做错了什么?

【问题讨论】:

  • 问题不应该是关于该主题的常见问题解答。不需要项目主页和维基百科链接。谢谢你的理解。干杯!

标签: c# node.js client-server zeromq


【解决方案1】:

我遇到了同样的问题(但我发出了通信 Node.JS -> Node.JS)。为了解决这个问题,我以前在发送方做sendersocket.connect("tcp://"+host+":"+port);,在接收方做receiversocket.bindSync("tcp://*:"+port);

希望这能解决您的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-30
    • 1970-01-01
    • 2022-10-14
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-26
    相关资源
    最近更新 更多