def connect_socket(self):
reply = None
for c in self.controllers:
self.logger.debug('Establishing socket connection to %s' % c)
tmp_sock = self.context.socket(zmq.REQ)
tmp_sock.setsockopt(zmq.RCVTIMEO, 2000)
tmp_sock.setsockopt(zmq.LINGER, 0)
tmp_sock.identity = self.identity
tmp_sock.connect(c)
# first ping the controller to see if it responds at all
msg = RPCMessage({'payload': 'ping'})
tmp_sock.send_json(msg)
try:
reply = msg_factory(tmp_sock.recv_json())
self.address = c
break
except:
traceback.print_exc()
continue
if reply:
# Now set the timeout to the actual requested
self.logger.debug("Connection OK, setting network timeout to %s milliseconds", self.timeout*1000)
self.controller = tmp_sock
self.controller.setsockopt(zmq.RCVTIMEO, self.timeout*1000)
else:
raise Exception('No controller connection')
评论列表
文章目录