Last active
April 11, 2019 23:45
-
-
Save dmazzer/0c7ba7db07557461d25c211f2cc7b64a to your computer and use it in GitHub Desktop.
Open Sound Controller client/server with Python-OSC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pythonosc.udp_client import SimpleUDPClient | |
ip = "127.0.0.1" | |
port = 8000 | |
client = SimpleUDPClient(ip, port) # Create client | |
client.send_message("/some/address", 123) # Send float message | |
client.send_message("/some/address", [1, 2., "hello"]) # Send message with int, float and string | |
client.send_message("/3/rotary1", 0.5) # Send message with int, float and string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pythonosc.dispatcher import Dispatcher | |
from pythonosc.udp_client import SimpleUDPClient | |
from pythonosc.osc_server import BlockingOSCUDPServer | |
from threading import Thread | |
server_ip = "0.0.0.0" # server instance - local IP to accept connections | |
client_ip = "192.168.30.104" # client instance - remote server IP to establish a connection | |
server_port = 8000 | |
client_port = 9000 | |
client = SimpleUDPClient(client_ip, client_port) # Create client | |
def loopback(path, data): | |
# client.send_message("/some/address", 123) # Send float message | |
# client.send_message("/some/address", [1, 2., "hello"]) # Send message with int, float and string | |
client.send_message(path, data) # Send float message | |
def print_handler(address, *args): | |
print(f"{address}: {args}") | |
def default_handler(address, *args): | |
print(f"DEFAULT {address}: {args}") | |
loopback(address, args) | |
dispatcher = Dispatcher() | |
dispatcher.map("/something/*", print_handler) | |
dispatcher.set_default_handler(default_handler) | |
def thread_server(): | |
print("thread ready") | |
server = BlockingOSCUDPServer((server_ip, server_port), dispatcher) | |
server.serve_forever() # Blocks forever | |
server.server_close() | |
th = Thread(target=thread_server) | |
th.start() | |
input("press enter") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pythonosc.dispatcher import Dispatcher | |
from pythonosc.osc_server import BlockingOSCUDPServer | |
def print_handler(address, *args): | |
print(f"{address}: {args}") | |
def default_handler(address, *args): | |
print(f"DEFAULT {address}: {args}") | |
dispatcher = Dispatcher() | |
dispatcher.map("/something/*", print_handler) | |
dispatcher.set_default_handler(default_handler) | |
ip = "127.0.0.1" | |
port = 1337 | |
server = BlockingOSCUDPServer((ip, port), dispatcher) | |
server.serve_forever() # Blocks forever |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment