Make sure that we close UDP sockets of local peer discovery
This commit is contained in:
parent
aa68e69a18
commit
e51788ac05
1 changed files with 9 additions and 6 deletions
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue