-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepn.py
More file actions
37 lines (26 loc) · 899 Bytes
/
epn.py
File metadata and controls
37 lines (26 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from multiprocessing import Process
import argparse
import zmq
parser = argparse.ArgumentParser()
parser.add_argument("port")
args = parser.parse_args()
context = zmq.Context()
def flp():
socket = context.socket(zmq.PULL)
socket.bind("tcp://*:%s" % args.port)
while True:
data = socket.recv()
print("Received: {}".format(data))
def icn():
socket_beat = context.socket(zmq.SUB)
socket_beat.connect("tcp://localhost:%s" % "5556")
socket_beat.setsockopt_string(zmq.SUBSCRIBE, "")
socket_beat_send = context.socket(zmq.PUSH)
socket_beat_send.connect("tcp://localhost:%s" % "5555")
while True:
target = int(socket_beat.recv())
print("Received Heartbeat")
socket_beat_send.send(str.encode("EPN {} is alive".format(args.port)))
if __name__ == "__main__":
Process(target=flp).start()
Process(target=icn).start()