-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions_osc_python3.py
More file actions
36 lines (29 loc) · 1.12 KB
/
Copy pathfunctions_osc_python3.py
File metadata and controls
36 lines (29 loc) · 1.12 KB
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
from pythonosc import udp_client
from pythonosc.dispatcher import Dispatcher
from pythonosc.osc_server import ThreadingOSCUDPServer
def create_client(ip, port):
"""Create a client for the UDP transfer"""
client = udp_client.SimpleUDPClient(ip, port)
return client
def create_send_close(ip, port, address, msg):
"""Create a client, send a message and kill the client"""
client = create_client(ip, port)
client.send_message(address, msg)
client._sock.close()
return client
def create_blocking_server(ip, port, addr):
"""Creates a blocking server and waits until it's prompted to close"""
def listener(address, *args):
"""Close the server upon a message"""
if args[0] == 'close_server':
# shutdown server before closing (must be threading server)
server.shutdown()
# initialize and configure the dispatcher
dispatcher = Dispatcher()
dispatcher.map(addr, listener)
# initialize the server
server = ThreadingOSCUDPServer((ip, port), dispatcher)
# Blocks forever
server.serve_forever()
# close the server
server.server_close()