##// END OF EJS Templates
specify heartbeat port at construction, not in run...
MinRK -
Show More
@@ -12,6 +12,7 b''
12 # Imports
12 # Imports
13 #-----------------------------------------------------------------------------
13 #-----------------------------------------------------------------------------
14
14
15 import socket
15 import sys
16 import sys
16 from threading import Thread
17 from threading import Thread
17
18
@@ -33,13 +34,16 b' class Heartbeat(Thread):'
33 self.addr = addr
34 self.addr = addr
34 self.ip = addr[0]
35 self.ip = addr[0]
35 self.port = addr[1]
36 self.port = addr[1]
37 if self.port == 0:
38 s = socket.socket()
39 s.bind(self.addr)
40 self.port = s.getsockname()[1]
41 s.close()
42 self.addr = (self.ip, self.port)
36 self.daemon = True
43 self.daemon = True
37
44
38 def run(self):
45 def run(self):
39 self.socket = self.context.socket(zmq.REP)
46 self.socket = self.context.socket(zmq.REP)
40 if self.port == 0:
47 self.socket.bind('tcp://%s:%i' % self.addr)
41 self.port = self.socket.bind_to_random_port('tcp://%s' % self.ip)
42 else:
43 self.socket.bind('tcp://%s:%i' % self.addr)
44 zmq.device(zmq.FORWARDER, self.socket, self.socket)
48 zmq.device(zmq.FORWARDER, self.socket, self.socket)
45
49
General Comments 0
You need to be logged in to leave comments. Login now