-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
27 lines (25 loc) · 1 KB
/
util.py
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
from memlist import *
# Broadcast Info to All Nodes
def broadcast(mlist, host, port, msg):
logging.info("Broadcast Message")
for client in mlist.lst:
if client['host'] != host or client['port'] != port:
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, (client['host'], client['port']))
logging.info('Broadcast to: %s:%d' %(client['host'], client['port']))
sock.close()
except (socket.error, socket.gaierror) as err_msg:
logging.exception(err_msg)
sock.close()
# Unicast Info to Introducer Node
def unicast(host, port, msg):
logging.info("Unicast Message")
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msg, (host, port))
logging.info('Broadcast to: %s:%d' %(host, port))
sock.close()
except (socket.error, socket.gaierror) as err_msg:
logging.exception(err_msg)
sock.close()