-
Notifications
You must be signed in to change notification settings - Fork 169
/
service.py
31 lines (27 loc) · 917 Bytes
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import sys
Param = sys.argv[1:]
if not Param:
from hooks import webservice
if webservice.start():
import hooks.monitor
hooks.monitor.StartUp()
else:
import _socket
Argv = ';'.join(["service"] + Param)
DataSend, XbmcMonitor, sock = f"EVENT {Argv}".encode('utf-8'), None, _socket.socket(_socket.AF_INET, _socket.SOCK_STREAM)
sock.setsockopt(_socket.SOL_SOCKET, _socket.SO_REUSEADDR, 1)
sock.setsockopt(_socket.IPPROTO_TCP, _socket.TCP_NODELAY, 1)
sock.settimeout(None)
for _ in range(60): # 60 seconds timeout
try:
sock.connect(('127.0.0.1', 57342))
sock.send(DataSend)
sock.recv(1024)
sock.close()
break
except:
if not XbmcMonitor:
import xbmc
XbmcMonitor = xbmc.Monitor()
if XbmcMonitor.waitForAbort(0.1):
break