-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlive.py
More file actions
73 lines (54 loc) · 2.42 KB
/
Alive.py
File metadata and controls
73 lines (54 loc) · 2.42 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/home/sofyan/anaconda3/bin/python
'''
How to run this process
- in the file of DKConfig.json, put the IPs of master and the ports of sub connection
which you will publish your messages
- ./Alive ip PortOfDownload PortOfUpload
'''
#############################################################################################################
# libraries
#############################################################################################################
import sys
import os
import time
import zmq
import json
import signal
import threading
##############################################################################################################
# Variable
##############################################################################################################
context = zmq.Context()
Alive = context.socket(zmq.PUB) # connect
MasterIP = None
MasterPortSub = None
MyInfo = {}
##############################################################################################################
# Connection
##############################################################################################################
def Connection():
Alive.connect("tcp://"+MasterIP+":"+MasterPortSub)
##############################################################################################################
# Function of connections
##############################################################################################################
def SendingMessage():
while True:
Alive.send_pyobj(MyInfo)
print("i have sent the message")
time.sleep(1)
##############################################################################################################
# Main
##############################################################################################################
if __name__ == "__main__":
# Initial values
with open('DKConfig.json') as config_file:
data = json.load(config_file)
MasterIP = data["MasterIP"]
MasterPortSub = data["MasterPortSub"]
ID = data['ID']
MyInfo["IP"] = 'localhost'
MyInfo["PortDownload"] = 100
MyInfo["PortUpload"] = 100
MyInfo["ID"] = ID
Connection()
SendingMessage()