From b1d409463be7bf54c5351412ef738e4073b9825b Mon Sep 17 00:00:00 2001 From: Artem30801 Date: Thu, 7 Mar 2019 19:15:45 +0300 Subject: [PATCH] Broadcast fix --- Drone/client.py | 2 +- Server/server.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Drone/client.py b/Drone/client.py index 0c9e2555..a1781a5a 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -40,7 +40,7 @@ def reconnect(t=2): print("Waiting for connection, attempt", attempt_count) try: clientSocket = socket.socket() - clientSocket.settimeout(3) + # clientSocket.settimeout(3) clientSocket.connect((host, port)) connected = True print("Connection successful") diff --git a/Server/server.py b/Server/server.py index 35089c1d..20433d3d 100644 --- a/Server/server.py +++ b/Server/server.py @@ -37,14 +37,15 @@ def auto_connect(): Client.clients[addr[0]].connect(c, addr) -def ip_broadcast(ip): +def ip_broadcast(ip, port): ip = ip broadcast_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP) broadcast_sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) broadcast_sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) while True: - msg = bytes(Client.form_command("server_ip ", ip), "UTF-8") + msg = bytes(Client.form_command("server_ip ", ip, ), "UTF-8") broadcast_sock.sendto(msg, ('255.255.255.255', 8181)) #TODO to config + print("Broadcast sent") time.sleep(5) @@ -325,6 +326,7 @@ def gui_update(): autoconnect_thread.start() broadcast_thread = threading.Thread(target=ip_broadcast, args=(ip, port, )) +broadcast_thread.start() if __name__ == '__main__': try: