-
Notifications
You must be signed in to change notification settings - Fork 1
/
async_server.py
35 lines (24 loc) · 845 Bytes
/
async_server.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
from pythonosc.osc_server import AsyncIOOSCUDPServer
from pythonosc.dispatcher import Dispatcher
import asyncio
def filter_handler(address, *args):
print(f"{address}: {args}")
dispatcher = Dispatcher()
dispatcher.map("/accelerometer", filter_handler)
ip = "192.168.0.171"
port = 9000
async def loop():
"""Example main loop that only runs for 10 iterations before finishing"""
i = 0
while(True):
i += 1
print(f"Loop {i}")
await asyncio.sleep(0.1)
async def init_main():
server = AsyncIOOSCUDPServer(
(ip, port), dispatcher, asyncio.get_event_loop())
# Create datagram endpoint and start serving
transport, protocol = await server.create_serve_endpoint()
await loop() # Enter main loop of program
transport.close() # Clean up serve endpoint
asyncio.run(init_main())