I am a beginner in OSC communication.
I have implemented communication using UDP in the past, but OSC is the first time.
I have read the Python OSC library documentation.
According to this document, OSC sends certain information to certain URLs such as "/filter".
OSC_Client.py
import argparse
import random
import time
from pythonosc import udp_client
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", default="127.0.0.1",
help="The ip of the OSC server")
parser.add_argument("--port", type=int, default=5005,
help="The port the OSC server is listening on")
args = parser.parse_args()
client = udp_client.SimpleUDPClient(args.ip, args.port)
for x in range(10):
client.send_message("/filter", random.random())
time.sleep(1)
The code on the receiving side also receives information by specifying a specific URL like "/filter".
OSC_Server.py
import argparse
import math
from pythonosc import dispatcher
from pythonosc import osc_server
def print_volume_handler(unused_addr, args, volume):
print("[{0}] ~ {1}".format(args[0], volume))
def print_compute_handler(unused_addr, args, volume):
try:
print("[{0}] ~ {1}".format(args[0], args[1](volume)))
except ValueError: pass
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--ip",
default="127.0.0.1", help="The ip to listen on")
parser.add_argument("--port",
type=int, default=5005, help="The port to listen on")
args = parser.parse_args()
dispatcher = dispatcher.Dispatcher()
dispatcher.map("/filter", print)
dispatcher.map("/volume", print_volume_handler, "Volume")
dispatcher.map("/logvolume", print_compute_handler, "Log volume", math.log)
server = osc_server.ThreadingOSCUDPServer(
(args.ip, args.port), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
However, the code for normal UDP is: It is possible to send a character string without specifying the URL, etc. and receive all the character string information by specifying the port.
Like UDP_Client.py and UDP_Server.py below.
UDP_Client.py
from socket import socket, AF_INET, SOCK_DGRAM
HOST = ''
PORT = 5000
ADDRESS = "127.0.0.1"
s = socket(AF_INET, SOCK_DGRAM)
while True:
msg = "testSend"
s.sendto(msg.encode(), (ADDRESS, PORT))
s.close()
UDP_Server.py
from socket import socket, AF_INET, SOCK_DGRAM
HOST = ''
PORT = 5000
s = socket(AF_INET, SOCK_DGRAM)
s.bind((HOST, PORT))
while True:
msg, address = s.recvfrom(8192)
print(f"message: {msg}\nfrom: {address}")
s.close()
I wonder if there is a way to get all the received data in OSC by specifying only the port number.
I want to analyze the contents of the software that communicates with OSC and know what kind of data is being sent. For that, I want to know if this can be done.
Knowing this is an old question, but I stumbled across it looking for help. If I understand what you were looking to do correctly, you just want to see ALL OSC messages instead of having to specify a path.
If that's the case, the good news is that is easy.
In your OSC_Server.py example, change this:
dispatcher.map("/filter", print)
To this:
dispatcher.map("/*", print)
This will use the built-in "print()" function to print out all the messages coming in via OSC on whatever port you specify. A bit surprised the documentation doesn't show this and explain a little better in the examples.
I hope this helps someone