What I am trying to do is to have a C++ ZeroMQ server with publisher role and connect NodeJS subscriber clients.
I was able to get nodeJS server + nodejs client examples working, but I am not able to connect it using C++.
C++ code:
#include "zmq.hpp"
// Convert string to 0MQ string and send to socket
auto s_send(zmq::socket_t & socket, const std::string & string) {
zmq::message_t message(string.size());
memcpy(message.data(), string.data(), string.size());
return socket.send(message, zmq::send_flags::none);
}
int main() {
std::cout << "Hello World!\n";
zmq::context_t ctx(1);
zmq::socket_t sock(ctx, ZMQ_PUB);
sock.bind("tcp://*:5555");
Sleep(1000);
while (true) {
s_send(sock, "Hello from the publisher.");
Sleep(1000);
}
}
NodeJS code:
var zmq = require('zeromq');
var sock = zmq.socket('sub');
sock.connect("tcp://127.0.0.1:5555");
console.log("Subscriber connected to port 5555");
sock.on('message', function(msg){
console.log('work: %s', msg.toString());
});
Any ideas what I am doing wrong? Is there any tutorial on interconnecting ZeroMQ from different languages? I was only able to find examples that use the same technologies on both side of the communication.