I'm recieving data using an OSC server and the data looks like this:
b'Person0/elements/alpha_absolute\x00,dddd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xbbP\x128\xe6/\xd4\x00\x00\x00\x00\x00\x00\x00\x00'
b'Person0/elements/alpha_absolute\x00,dddd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xbbOw\x8f\xa7\xac\x10\x00\x00\x00\x00\x00\x00\x00\x00'
b'Person0/elements/alpha_absolute\x00,dddd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xbb\x10\x1f\xf2JN\xed\x00\x00\x00\x00\x00\x00\x00\x00'
b'Person0/elements/alpha_absolute\x00,dddd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xbah[\nY\xe9K\x00\x00\x00\x00\x00\x00\x00\x00'
b'Person0/elements/alpha_absolute\x00,dddd\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00?\xb8\x8f\x97\xb1\x04\xc4B\x00\x00\x00\x00\x00\x00\x00\x00'
The data title is: Person0/elements/alpha_absolute and the arguments is: dddd (4 floats)
The rest seems to be encoded. I don't understand how to get the 4 floats I'm supposed to recieve
This is my whole code:
import socket
print('Program Initiated')
UDP_IP = "127.0.0.1"
UDP_PORT = 6000
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(2048) # buffer size is 1024 bytes
if 'alpha' in str(data):
print(data)
Use this:
Since you don't know anything about the structure, this is based on the following guesses:
titlefield is a string of maximally 32 bytes long because it is a text string and the 32rd byte is always a0.argsfield is a string of maximally 8 bytes long because that's what is left when you assume …double float. The last 8 bytes are always all0. That is a valid double number (0, actually); the 8 bytes before them are all valid floats in big-endian format, and that makes 2 valid floats. So, counting backwards, 16 more zeroes must be the other 2 values, and the few bytes left must belong to theargsfield.Running the
unpackon the provided data gives you this result:where about the only thing remarkable is that from the four float items, only one seems actually used.