我有这个场景:客户端尝试发送到服务器,但服务器处于脱机状态。socket.send(request, 0); 在 java Timer 线程内部:
这是 ZMQ.Socket m_socket 在线程外启动的线程 run()
public void run() {
m_socket.send(request, 0);
byte[] reply = m_socket.recv(0);
//get seperator
byte[] empty1 = m_socket.recv(0);
//get secound frame
byte[] byteFileStruct = m_socket.recv(0);
if(null!=reply) // this is indication that the server is offline , is there better way to check ?
{
......
}
}
现在 Timer 再次触发 run() 方法,当它执行 m_socket.send(request, 0); 在第二轮我得到:
Exception in thread "Timer-0" org.zeromq.ZMQException: Operation cannot be accomplished in current state(0x9523dfb)
at org.zeromq.ZMQ$Socket.send(Native Method)
at com.agent.core.Poller$PollarWorker.run(Poller.java:155)
at java.util.TimerThread.mainLoop(Unknown Source)
at java.util.TimerThread.run(Unknown Source)
我需要每轮创建新的套接字吗?就是这样:
m_context = ZMQ.context(1);
m_socket = m_context.socket(ZMQ.REQ);
m_socket.setReceiveTimeOut(2000);
m_socket.setSendTimeOut(2000);
m_socket.connect (sControllerDomain);