F.R.D
F.R.D

Reputation: 173

OSC communication from scsynth to python with PyOsc

Communication from Python to scsynth via pyosc goes well, but instead when trying to receive in Python osc messages sent from scsynth audio server (just scsynth, not SuperCollider), I don't understand how to get the port scsynth is sending to.

If I try to send a "/notify" message to scsynth it should reply with the sending address, but with pyosc I can't set a listener on the same port as the sending one, and so I can't retrieve the information that should come back.

Any suggestions about how to do that?

Upvotes: 0

Views: 912

Answers (2)

Charles Martin
Charles Martin

Reputation: 358

You can accomplish this by using OSCClient.setServer to tell your OSC client to use the server's socket for transmission. Here's an example to illustrate this where the OSC message is send and received at socket 8000:

import OSC

def handle_message(address, tags, contents, source):
    # prints out the message
    print(address)
    print(source)

server = OSC.OSCServer(("localhost",8000))
server.addMsgHandler("/test", handle_message)

msg = OSC.OSCMessage("/test", [1])

client = OSC.OSCClient()
client.setServer(server)
client.connect(("localhost", 8000))
client.send(msg)

server.serve_forever()

Upvotes: 1

caseyanderson
caseyanderson

Reputation: 530

I am almost positive the sender and the receiver have to be on different ports. A port used for receiving cannot also be used for sending simultaneously.

regarding sending OSC messages back to pyosc I do not understand why you wouldnt use NetAddr.new and then .sendMSg(). For example (this is from the documentation on OSC Communication):

b = NetAddr.new("127.0.0.1", 7771);
b.sendMsg("/hello", "there");

More info here.

If you wanted automatic reply from SC then you could just write a way to trigger a responding .sendMsg into your OSCDef or OSCFunc, for example, which could simply wait for the initial message from python and respond with whatever you want python to get back.

Upvotes: 0

Related Questions