From: Sebastian Golasch Date: Sat, 4 Feb 2017 14:38:10 +0000 (+0100) Subject: feat(service): Dynamic port allocation X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;ds=sidebyside;h=c1cb01ec0027c7c5a1c67934df407b4820a5686a;hp=864a936a55c4862092db36f5ec0cce2f70f5e647;p=plugin.video.netflix.git feat(service): Dynamic port allocation --- diff --git a/service.py b/service.py index 8600979..2af9813 100644 --- a/service.py +++ b/service.py @@ -1,10 +1,22 @@ import threading import SocketServer import xbmc +import xbmcaddon +import socket from resources.lib.common import log from resources.lib.MSLHttpRequestHandler import MSLHttpRequestHandler -PORT = 8000 +def select_unused_port(): + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.bind(('localhost', 0)) + addr, port = s.getsockname() + s.close() + return port + +addon = xbmcaddon.Addon() +PORT = select_unused_port() +addon.setSetting('msl_service_port', str(PORT)) +log("Picked Port: " + str(PORT)) Handler = MSLHttpRequestHandler SocketServer.TCPServer.allow_reuse_address = True server = SocketServer.TCPServer(('127.0.0.1', PORT), Handler)