What is the proper way to wait for connections?

自古美人都是妖i 提交于 2019-12-04 04:48:39

The best solution to your sleep on the server side is to create a socket poller and poll on the pull socket until a message is received. This avoids wasteful sleeps, and makes for generally tighter code.

On the client side the best solution is probably to create two sockets (one for sending messages, one for receiving), and have the server announce its presence ready for the client to send the message. Because ZeroMQ is efficient at handling multiple connections, this solution will work very well.

somdoron

both receive and send can wait until can be executed, you passed true to dontWait parameter on your example, just remove it and it will send the message when it can.

For the receive you don't have to sleep because it will wait until message is available.

As suggested using Poller is also a solution (you can poll when the socket can send and when messages are ready to be consumed), take a look at the testing for poller class: https://github.com/zeromq/netmq/blob/3.3.3-rc5/src/NetMQ.Tests/PollerTests.cs.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!