Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

How to receive a reply when using REQ socket? #583

Open
pronebird opened this issue Dec 12, 2016 · 3 comments
Open

How to receive a reply when using REQ socket? #583

pronebird opened this issue Dec 12, 2016 · 3 comments

Comments

@pronebird
Copy link

I am looking at some py bindings for zeromq and what they do for REQ socket is:

socket.send ("Hello")
message = socket.recv()

.recv() is undefined in zeromq.node and I don't see an alternative for that either. Would you mind pointing me in the right direction?

@pronebird
Copy link
Author

pronebird commented Dec 12, 2016

OK I figured that message event is fired instead.

req_socket.on('message', function (message) {
  console.log('<- ' + message.toString('utf8'));
});

@pronebird
Copy link
Author

pronebird commented Dec 14, 2016

Reopening this because it's HIGHLY inconvenient to work with REQ socket this way. I'll explain why. If you have RPC interface that takes data, performs request and returns response, you have to do some magic dance to funnel received response back to RPC implementation, also you have to take care of execution order, etc. It would be great if there was a way to send request with callback that would be called with response, i.e:

socket.send(req, function (resp) {
   // do something
});

@pronebird pronebird reopened this Dec 14, 2016
@patrickjane
Copy link

I agree to you, in that it would need extra code/multipart messages to match responses to previous requests in the 'message'-event callback.

Your suggestion looks much better.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants