broadcaster = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
broadcaster.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
broadcaster.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
def send_broadcast_thread():
msg = "test"
while True:
# TODO: write logic for sending broadcasts.
broadcaster.sendto(msg.encode(), ('255.255.255.255', get_broadcast_port()))
print(msg.encode())
time.sleep(1)
def receive_broadcast_thread():
broadcaster.bind(('', get_broadcast_port()))
while True:
data, (ip, port) = broadcaster.recvfrom(4096)
print(f"RECV: {data} FROM: T{ip}:{port}")
Я получаю эту ошибку, когда пытаюсь запустить этот код. Я вызываю каждую их функцию в отдельном потоке демона.
line 88, in receive_broadcast_thread
broadcaster.bind(('', get_broadcast_port())) OSError: [Errno 22] Invalid argument