init test
This commit is contained in:
1 parent
40f64c8ebb
commit
a4f6d78ab9
1 file changed
+32
+32
@@ -0,0 +1,32 @@
|
|||||||
|
from datetime import datetime, timezone
|
||||||
|
import socket
|
||||||
|
|
||||||
|
INTRODUCER_IP = "172.22.156.3"
|
||||||
|
IP = socket.gethostbyname(socket.gethostname())
|
||||||
|
SERVER_PORT = 6767
|
||||||
|
INTRODUCER_FLAG = (INTRODUCER_IP == IP)
|
||||||
|
|
||||||
|
#check if this VM is the introducer and add it self
|
||||||
|
members_list = {}
|
||||||
|
if INTRODUCER_FLAG:
|
||||||
|
members_list[(IP, PORT)] = {
|
||||||
|
"heart_beat": 1,
|
||||||
|
"last_seen": utc_time()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#start UDP socket
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
server.bind((IP, SERVER_PORT))
|
||||||
|
|
||||||
|
if not INTRODUCER_FLAG:
|
||||||
|
server.sendto(b"JOIN", (INTRODUCER_IP, SERVER_PORT))
|
||||||
|
|
||||||
|
while True:
|
||||||
|
data, addr = server.recvfrom(4096)
|
||||||
|
|
||||||
|
#increment heart beat
|
||||||
|
|
||||||
|
#utc time
|
||||||
|
def utc_time():
|
||||||
|
return datetime.now(timezone.utc)
|
||||||
Reference in new issue
Block a user