The Peer Object¶
The Peer object is the central component of PyOSC, responsible for managing the sending and receiving of OSC messages over a network. It encapsulates the network connection details, message dispatching, and provides an interface for interacting with OSC messages.
Initialization¶
To create a Peer object, you need to provide the following parameters:
address: The IP address or hostname of the remote peer.port: The port number on which the remote peer is listening.mode: The transport mode, eitherOSCModes.UDPorOSCModes.TCP.framing: The OSC framing protocol,OSCFraming.OSC10orOSCFraming.OSC11.
Example:
from pyosc import Peer, OSCModes, OSCFraming
peer = Peer(
"127.0.0.1",
8001,
mode=OSCModes.UDP,
framing=OSCFraming.OSC11,
UDP_bind_address="127.0.0.1",
UDP_bind_port=8002
)
Note
When using UDP, it is important to specify the UDP_bind_address and UDP_bind_port to bind the socket for receiving messages.
Sending Messages¶
To send an OSC message, you must first create an OSCMessage object.
Example:
from pyosc import OSCMessage, OSCInt, OSCString
message = OSCMessage(
address="/test/ping", #(1)!
args=(
OSCString(value="Hello, World!"), #(2)!
) #(3)!
)
- The OSC address to send the message to.
- Arguments contain a
valueattribute, which is where the actual value of the argument is stored. - The
argsparameter is a tuple of OSC argument objects, which can be of various types (e.g.,OSCInt,OSCString, etc.).