node-nanomsg: Pub/Sub stops after first message has been received.
I am absolutely new to nanomsg, so I might be doing something really stupid, but I can’t get this simple PUBSUB example to work:
var nano = require('nanomsg');
var addr = 'tcp://127.0.0.1:7789'
var pub = nano.socket('pub');
pub.bind(addr);
var sub1 = nano.socket('sub');
sub1.on('data', function (buf) {
console.log('sub1:' + String(buf));
});
sub1.chan(['topic1'])
sub1.connect(addr);
var sub2 = nano.socket('sub');
sub2.on('data', function (buf) {
console.log('sub2:' + String(buf));
});
sub2.chan(['topic2'])
sub2.connect(addr);
setInterval(function () {
console.log('sending');
pub.send("topic1 Hello from nanomsg!");
console.log('sent');
}, 1000);
Running this gives me:
sending
sent
sub1:topic1 Hello from nanomsg!
And then there is nothing more (even if the node process does not exit). I would expect the setInterval to do this repeatedly, but after the first message has been received there is nothing more.
Any ideas? I have tried this on nodejs 5.11.0 on my Mac and on 6.2.0 on an Ubuntu machine.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 30 (3 by maintainers)
k thanks, yea i’m not a fan of this code: https://github.com/nickdesaulniers/node-nanomsg/blob/master/lib/index.js#L440
We need to fix this