From 16ddf870d2832d36166efc530dd811569edde53c Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Sun, 8 May 2022 11:02:57 +0200 Subject: [PATCH] Select stream port from predefined range (#290) --- music_assistant/helpers/util.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/music_assistant/helpers/util.py b/music_assistant/helpers/util.py index e121d40e..2060de83 100755 --- a/music_assistant/helpers/util.py +++ b/music_assistant/helpers/util.py @@ -5,7 +5,6 @@ import asyncio import os import platform import socket -import socketserver import tempfile from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypeVar @@ -182,11 +181,10 @@ def is_port_in_use(port: int) -> bool: def select_stream_port() -> int: - """Automaticlaly find available stream port, prefer the default 8095.""" - if not is_port_in_use(8095): - return 8095 - with socketserver.TCPServer(("localhost", 0), None) as _sock: - return _sock.server_address[1] + """Automatically find available stream port, prefer the default 8095.""" + for port in range(8095, 8195): + if not is_port_in_use(port): + return port def get_folder_size(folderpath): -- 2.34.1