Skip to content

Instantly share code, notes, and snippets.

@messa
Last active April 29, 2016 21:54
Show Gist options
  • Save messa/862638ab44ca65f712fe4d6ef79aeb67 to your computer and use it in GitHub Desktop.
Save messa/862638ab44ca65f712fe4d6ef79aeb67 to your computer and use it in GitHub Desktop.
node zeromq problem demonstration for https://github.com/JustinTulloss/zeromq.node/issues/523
var zmq = require('zmq');
var socket = zmq.socket('dealer');
socket.connect('tcp://127.0.0.1:3333');
socket.on('message', function(payload) {
console.info('Received:', payload.toString());
});
console.info('Sending...');
socket.send(["msg1"]);
socket.send(["msg2"]);
setInterval(function() {
console.info('Calling _flushReads');
socket._flushReads();
}, 3000)
$ npm version
{ test: '1.0.0',
npm: '3.8.6',
ares: '1.10.1-DEV',
http_parser: '2.7.0',
icu: '56.1',
modules: '47',
node: '5.11.0',
openssl: '1.0.2g',
uv: '1.8.0',
v8: '4.6.85.31',
zlib: '1.2.8' }
$ cat /etc/debian_version
8.4
$ uname -a
Linux messai7 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2 (2016-04-08) x86_64 GNU/Linux
$ dpkg -l | grep zmq
ii libzmq3:amd64 4.0.5+dfsg-2+deb8u1 amd64 lightweight messaging kernel (shared library)
ii libzmq3-dev:amd64 4.0.5+dfsg-2+deb8u1 amd64 lightweight messaging kernel (development files)
ii python-zmq 14.4.0-1 amd64 Python bindings for 0MQ library
ii python3-zmq 14.4.0-1 amd64 Python3 bindings for 0MQ library
$ ./server.py >/dev/null &
[1] 5868
# this is how it should be - response is received immediately:
$ npm run-script client
> [email protected] client /home/messa/code/pokusy/bug-node-zmq
> node client.js
Sending...
Received: msg1
Received: msg2
Calling _flushReads
^C
# but sometimes, responses are received only after explicitly calling _flushReads:
$ npm run-script client
> [email protected] client /home/messa/code/pokusy/bug-node-zmq
> node client.js
Sending...
Calling _flushReads
Received: msg1
Received: msg2
Calling _flushReads
^C
{
"name": "test",
"version": "1.0.0",
"description": "",
"dependencies": {
"zmq": "^2.15.0"
},
"devDependencies": {},
"scripts": {
"client": "node client.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
#!/usr/bin/env python3
import zmq
zsock = zmq.Context().socket(zmq.ROUTER)
zsock.bind('tcp://127.0.0.1:3333')
while True:
parts = zsock.recv_multipart()
zsock.send_multipart(parts)
print(parts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment