java 如何检查 JZMQ 套接字是否已连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15184841/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:45:22  来源:igfitidea点击:

How to check if JZMQ socket is connected

javazeromqjzmq

提问by Michal Z m u d a

Is there way to check if JZMQ (java binding of zmq) socket is connected?

有没有办法检查JZMQ(zmq的java绑定)套接字是否连接?

ZContext zmqContext = new ZContext();
ZMQ.Socket workerSocket = zmqContext.createSocket(ZMQ.DEALER);
workerSocket.setIdentity("ID".getBytes());
workerSocket.connect("tcp://localhost:5556");

After code above I would like to check if workerSocket is connected. It would be nice to check connection status.

在上面的代码之后,我想检查 workerSocket 是否已连接。检查连接状态会很好。

回答by raffian

No, there's no method in the API to check if a socket is connected.

不,API 中没有方法来检查套接字是否已连接。

ZeroMq abstracts the network; client and server connections are completely transparent to the peer making the connection. A client or server may send messages to non-existent peers; no errors will be generated; instead, they'll queue up in socket buffers based on HWM config.

ZeroMq 抽象了网络;客户端和服务器连接对建立连接的对等方是完全透明的。客户端或服务器可能会向不存在的对等点发送消息;不会产生错误;相反,它们将根据 HWM 配置在套接字缓冲区中排队。

To check for peer availability, do it manually using a synchronous request/reply heartbeat with a timeout factor; here's an example, hope it helps!

要检查对等可用性,请使用带有超时因子的同步请求/回复心跳手动执行;这是一个例子,希望它有帮助!

Check out samples for request/reply here! https://github.com/imatix/zguide/tree/master/examples/

在此处查看样品以获取请求/回复! https://github.com/imatix/zguide/tree/master/examples/