from pythonosc import dispatcher
from pythonosc import osc_server
import time

def joint_handler(address, *args):
    print(args)
    time.sleep(0.3)

def main():
    ip = "0.0.0.0"  # Listen on all network interfaces
    port = 5005    # Must match the sender's port in `joint_state_osc.py`

    # Create dispatcher and register callback
    disp = dispatcher.Dispatcher()
    #disp.map("/joint_states", joint_handler)
    disp.map("/SYNC", joint_handler)

    server = osc_server.ThreadingOSCUDPServer((ip, port), disp) # Start OSC server
    
    try:
        server.serve_forever()  # Keep server running
    except KeyboardInterrupt:
        print("")

if __name__ == "__main__":
    main()