How do you send a message using pyOSC?

I am very new to python and even less familiar with pyOSC. Can someone post a simple example of how to send a string message from my computer to another computer? I looked at this pyOSC link , which gave me some guidance, but I'm not sure why addressSet () accepts a "start". Is it a function that receives a message at the other end, or is it something else?

I really appreciate any advice you can provide!

+4
source share
1 answer

OSC has a concept of message address that is different from the network address of the device you are connecting to. The idea is that the message you send can be redirected to one of many different handlers at the other end of the network connection. Each handler has its own address, which is usually indicated by the prefix '/'.

Using the same client code from the question you are referring to :

import OSC

c = OSC.OSCClient()
c.connect(('127.0.0.1', 57120))   # localhost, port 57120
oscmsg = OSC.OSCMessage()
oscmsg.setAddress("/startup")
oscmsg.append('HELLO')
c.send(oscmsg)

First run this server code:

import OSC

def handler(addr, tags, data, client_address):
    txt = "OSCMessage '%s' from %s: " % (addr, client_address)
    txt += str(data)
    print(txt)

if __name__ == "__main__":
    s = OSC.OSCServer(('127.0.0.1', 57120))  # listen on localhost, port 57120
    s.addMsgHandler('/startup', handler)     # call handler() for OSC messages received with the /startup address
    s.serve_forever()

Then start the client from another terminal. On the server side, you should get something like:

OSCMessage '/startup' from ('127.0.0.1', 55018): ['HELLO']

, pyOSC, - . OSC.py . , , , , .

+10

Source: https://habr.com/ru/post/1608673/


All Articles