Make sure that we close UDP sockets of local peer discovery

This commit is contained in:
shortcutme 2018-04-18 13:11:50 +02:00
parent aa68e69a18
commit e51788ac05
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -1,6 +1,7 @@
import socket
import logging
import time
from contextlib import closing
import msgpack
@ -90,6 +91,7 @@ class BroadcastServer(object):
message_part["sender"] = self.sender_info
self.log.debug("Send to %s: %s" % (addr, message_part["cmd"]))
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto(msgpack.packb(message_part), addr)
@ -108,6 +110,7 @@ class BroadcastServer(object):
for my_ip in my_ips:
try:
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as sock:
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.bind((my_ip, 0))