-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with Raspberry Pico PI - Server mode #12
Comments
You can either:
|
Ok, great thanks - though curious why there is Client class and no Server class ? |
Short answer: because it isn't really needed and everyone's requirements are different. Long answer: The two main tasks for a server are a) to open a communication channel (e.g. an UDP socket) and listen on it and b) to dispatch incoming client messages to handler functions. This can be as minimal as in To handle clients efficiently, the server should employ some kind of parallel request handling. The two main ways to achieve that on MicroPython are asyncio or threads, with the latter not available on every MicroPython port or platform. The right choice also depends on the structure of your application and the frequency and size of client requests you expect and how long you want to handle them. IMHO answering these kind of design questions is out of scope for the core of OSC handling, so You need to implement your own server or adapt the given examples if:
|
Ok, thanks for swift and thorough reply. """A minimal, blocking OSC UDP server."""
import socket
from uosc.server import handle_osc
DEFAULT_ADDRESS = '0.0.0.0'
DEFAULT_PORT = 9001
MAX_DGRAM_SIZE = 1472
def run_server(saddr, port, handler=handle_osc):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ai = socket.getaddrinfo(saddr, port)[0]
sock.bind(ai[-1])
print("Listening for OSC messages on:", saddr, port)
try:
while True:
data, caddr = sock.recvfrom(MAX_DGRAM_SIZE)
handler(data, caddr)
finally:
sock.close()
print("Bye!")
try:
run_server(DEFAULT_ADDRESS, DEFAULT_PORT)
except KeyboardInterrupt:
pass Tested and it works on Pico PI :) Obviously the way to go would be using async version running on separate thread (2nd core of RP) to separate time critical code. My question now is - is it possible to have Client and Server both running simultaneously on the same thread (presumably using asyncio) so I can send and receive OSC messages at the same time ? If I get such setup working I intend to share the example code so others can use it as a blueprint for such (kind of likely) scenario :) |
Hi !
I was able to run the Client code without any issues (so far) on Raspberry Pico PI W but have no luck with the Server code since it seems to require fflib which in turn uses ffi package and I can't find any implementation for Pico (it seems it's only supported in unix port ?). Is there any workaround, is the iff really necessary to provide OSC Server on microcontroller hardware ?
Kind of surprised that it seems it's the only OSC lib for micropython given the versatility and widespread use in makers community (especially in context of DIY music controllers) so hope some robust implementation of both Server and Client on micropython boards would be possible.
The text was updated successfully, but these errors were encountered: