-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (27 loc) · 1.23 KB
/
main.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
32
33
34
35
36
37
from pythonosc import dispatcher, osc_server
from handler_factory import HandlerFactory
from logger import log
from config import get_config
CONFIG = {} # Global
def handle_msg(client_address, address, *args):
""" Gets called when a mesage is received by the OSC Server"""
caller_full_ip = f"{client_address[0]}:{client_address[1]}"
log.info(f"Message received [{caller_full_ip}] '{address}' {args}")
handler = HandlerFactory.get_handler(address)
if handler:
handler.handle(address, *args)
else:
log.warning(f"Message without handler [{caller_full_ip}] '{address}' {args}")
def startServer():
""" Config and execute the OSC Server """
ip = get_config("server_ip") # Server ip, this IP will works for localhost.
port = int(get_config("server_port")) # Port in case you have more than one OSC Server.
# Dispatcher configuration to assign halders for the msgs
disp = dispatcher.Dispatcher()
disp.set_default_handler(handle_msg, True)
# Server start
server = osc_server.ThreadingOSCUDPServer((ip, port), disp)
log.info(f"OSC Server started in {ip}:{port}")
server.serve_forever() # Mantiene el servidor activo
if __name__ == "__main__":
startServer()