From 020bd59766d0780e4264d58d4847b3cd2f5e03ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Str=C3=A5b=C3=B8?= Date: Sun, 15 Nov 2020 18:50:54 +0100 Subject: [PATCH] Fixes jellyfin/jellyfin-kodi#421 Jellyfin autodiscovery is IPv4 broadcast only. We're not binding to a specific port, no need for SO_REUSEADDR. IP_MULTICAST_LOOP belongs to IPPROTO_IP https://tldp.org/HOWTO/Multicast-HOWTO-6.html and SO_REUSEADDR belongs to SOL_SOCKET https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options --- jellyfin_kodi/jellyfin/connection_manager.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/jellyfin_kodi/jellyfin/connection_manager.py b/jellyfin_kodi/jellyfin/connection_manager.py index 3dabcccc..fa2ffc8c 100644 --- a/jellyfin_kodi/jellyfin/connection_manager.py +++ b/jellyfin_kodi/jellyfin/connection_manager.py @@ -213,11 +213,7 @@ class ConnectionManager(object): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.settimeout(1.0) # This controls the socket.timeout exception - - sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20) sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - sock.setsockopt(socket.SOL_IP, socket.IP_MULTICAST_LOOP, 1) - sock.setsockopt(socket.IPPROTO_IP, socket.SO_REUSEADDR, 1) LOG.debug("MultiGroup : %s", str(MULTI_GROUP)) LOG.debug("Sending UDP Data: %s", MESSAGE) @@ -232,6 +228,8 @@ class ConnectionManager(object): return servers while True: + data = None + addr = None try: data, addr = sock.recvfrom(1024) # buffer size servers.append(json.loads(data)) @@ -240,6 +238,9 @@ class ConnectionManager(object): LOG.info("Found Servers: %s", servers) return servers + except json.JSONDecodeError: + LOG.warning("Unable to decode %r from %r.", data, addr) + except Exception as e: LOG.error(traceback.format_exc()) LOG.exception("Error trying to find servers: %s", e)