-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sending Uint8Array over PUB/SUB (v4.6.0) #268
Comments
Futhermore, if I try converting the Uint8Array to a buffer, the message is never received Here is a minimal working : const zmq = require('zeromq')
const { expect } = require('chai')
const ZMQ_ADDR = 'tcp://127.0.0.1:5000'
let sndArr = new Uint8Array([21,31]);
let buf = Buffer.from(sndArr);
let pub = zmq.socket('pub');
pub = zmq.socket('pub')
pub.bindSync(ZMQ_ADDR)
let sub = zmq.socket('sub');
sub.connect(ZMQ_ADDR);
sub.subscribe('topic');
sub.on('message', function(topic, message) {
let recvArr = new Uint8Array(message)
expect(recvArr.toString()).to.equal(sndArr.toString())
});
pub.send(['topic', buf]) This results in the program hanging forever because the message is never received |
I tried using zeromq-ng (I was inspired by this issue) which solved my problem. Here is a minimal working example : // subscriber.js
const { expect } = require('chai')
const zmq = require("zeromq-ng")
let sndArr = new Uint8Array([21,31]);
async function run() {
const sock = new zmq.Subscriber
sock.connect("tcp://127.0.0.1:5000")
sock.subscribe("topic")
console.log("Subscriber connected to port 5000")
while (!sock.closed) {
const [topic, msg] = await sock.receive()
let recvArr = new Uint8Array(msg)
expect(recvArr.toString()).to.equal(sndArr.toString())
console.log("Received valid Uint8Array")
}
}
run() // publisher.js
const zmq = require("zeromq-ng")
let sndArr = new Uint8Array([21,31]);
let buf = Buffer.from(sndArr);
async function run() {
const sock = new zmq.Publisher
await sock.bind("tcp://127.0.0.1:5000")
console.log("Publisher bound to port 5000")
while (!sock.closed) {
console.log("Sending Uint8Array")
await sock.send(["topic", buf])
await new Promise(resolve => setTimeout(resolve, 500))
}
}
run() Of course, this does not mean that the issue was fixed, rather that I will use zeromq-ng until it is (or until zeromq-ng is integrated into zeromq.js). |
Here is an update: a 6.0 beta has been released that incorporates all changes from ZeroMQ-NG. The API is exactly the same as that of the last ZeroMQ-NG release. If there are any specific problems remaining please open a new issue! |
Hi,
I am trying to figure out how to send an Uint8Array over a PUB/SUB pattern.
Currently, the array I publish differs from the one I receive. Could this be caused
by the fact that the array is not encoded into binary and instead text?
Here is a minimal working example of this issue :
Example output :
The text was updated successfully, but these errors were encountered: