Closed JSYRD closed 6 months ago
First of all you should only listen to the socket messages once:
@override
void initState() {
// omitted codes
enterQueueSocket = ZMQHelper.getNewSocket(Config.replyUrl, SocketType.req);
enterQueueSocket.messages.listen((event) {
for (var element in event) {
print(utf8.decode(element.payload));
}
});
// omitted codes
super.initState();
}
void enterQueue() {
enterQueueSocket.send(utf8.encode(json.encode({
"enterQueue": true,
"name": _nameController.text,
"clientId": "${ZMQHelper.context.hashCode}"
})));
}
I would also recommend using a dealer socket, because if you send a message while the reply has not been received yet, you will also get an exception. With the dealer socket being asynchronous you don't run into this issue.
Thank you for your help! Actually, I've tried this after I rep this issue, but the result was the same. So I searched for the async ways to solve this problem, using dealer. The way you use dealer doesn't work for me at all. I've found a new way to use dealer-rep. I think I may push an pr later.
Would the solution provided in #21 work for you? Maybe we need to have different sockets for synchronous socket types that are not handled by the internal loop.
Thanks! It seems shall work for me. But given the logic that the plugin works, using dealer
instead is a better choice. I've added notes about how to use dealer/rep pattern correctly in this pr #29 .
Would the solution provided in #21 work for you? Maybe we need to have different sockets for synchronous socket types that are not handled by the internal loop.
This would be perfect for my use-case, and also what I had expected to have available
I'm a noob in ZeroMQ. The guide says:
But there's no such method like
zmq_recv
, so I tried to usesocket.messages.listen()
to receive. It DID receive messages, but always throwing exceptions:I have no idea how to fix this.
The source code is below:
I'd appreciate it if anyone would help me.