sc3.base.netaddr module¶
NetAddr.sc
-
class
NetAddr
(hostname, port)¶ Bases:
object
NetAddr’s objects represent target addresses to send messages to, or establish connections with, using UDP or TCP transport protocols.
When initialized in real time, the library sets up a default UDP port with the default interface to send and receive OSC data. The default port is 57120 but it can change if it is being used by another application. The actual port can be queried through the ‘lang_port()’ static method.
More UDP ports can be open as local endpoints with ‘main.open_udp_port’ and closed with ‘main.close_udp_port’. To change the output UDP port of a NetAddr object use ‘change_output_port’. TCP connections can be stablished with ‘connect’ and closed with ‘disconnect’ from an existing NetAddr object. Note that differently from UDP protocol, which is connectionless, TCP connections are client connections that can’t be used for serving purposes as independent ports.
-
property
hostname
¶ Address name.
-
property
addr
¶ Address name as int.
-
property
port
¶ Address port.
-
property
proto
¶ Return the transport protocol.
-
property
is_local
¶ Return true if the address is in localhost.
-
property
local_endpoint
¶ Return the bind address as a tuple (hostname, port).
-
change_output_port
(port)¶ Change UDP local endpoint.
-
static
lang_port
()¶ Return the default UPD port of the language.
-
static
lang_endpoints
()¶ Return a list of all active local endpoints as (hostname, port, proto).
-
connect
(on_complete=None, on_failure=None, local_port=None, timeout=3)¶ Stablish a TCP connection to this address.
-
disconnect
()¶ Close TCP connection to this address.
-
property
is_connected
¶ Return True if a TCP connection is stablished.
-
has_bundle
()¶ Polymorphic method used to differentiate NetAddr from BundleNetAddr by avoiding type checking.
-
send_msg
(*args)¶ Send an OSC message to the server.
- Parameters
*args (
items
) – OSC address followed by zero or more values that compose the message.
Notes
Invoked as:
addr.send_msg('/osc_addr', p1, p2, ...)
-
send_bundle
(time, *elements)¶ Send an OSC bundle to the server.
- Parameters
time (
int | float | None
) – Latency time from now. If time is None or negative the timetag is set to immediately. Nested bundles can have their own latency but must be >= to the enclosing bundle latency.*elements (
lists
) – Each element is a list in the form of an OSC message or bundle.note (.) –
bundle can be only composed of messages. (generated) –
Notes
Elements lists representing messages or bundles. Invoked as:
addr.send_bundle(1, ['/msg', ...], [1.2, ['/bndl', ...], ...], ...)
-
send_clumped_bundles
(time, *elements)¶ This method is used to send bundles larger than UDP datagram size as successive sub-clumped packages.
-
send_status_msg
()¶ Send ‘/status’ message to the server.
The server will respond with ‘/status.reply’.
-
sync
(condition=None, latency=None, elements=None)¶ Generator method that internally manages server’s ‘/sync’ message. Because it’s used to synchronize bundles sent to the server it is primarly used through Server’s
sync
wrapper method.- Parameters
condition (
Condition
) – An optional instance of Condition that will be used to wait for the reply.latancy (
int | float
) – Bundle’s latency as insend_bundle
.elements (
list
) – A list of lists as OSC messages which will be sent before the ‘/sync’ message.
-
property
-
class
BundleNetAddr
(target, arg_list=None, send=True)¶ Bases:
sc3.base.netaddr.NetAddr
This class is a context manager that acts as a proxy of the current NetAddr and collects single messages to be sent as a bundle. It’s main use is through ‘bind’ method of the server objects.
-
has_bundle
()¶ Polymorphic method used to differentiate NetAddr from BundleNetAddr by avoiding type checking.
-
send_msg
(*args)¶ Send an OSC message to the server.
- Parameters
*args (
items
) – OSC address followed by zero or more values that compose the message.
Notes
Invoked as:
addr.send_msg('/osc_addr', p1, p2, ...)
-
send_bundle
(time, *elements)¶ Send an OSC bundle to the server.
- Parameters
time (
int | float | None
) – Latency time from now. If time is None or negative the timetag is set to immediately. Nested bundles can have their own latency but must be >= to the enclosing bundle latency.*elements (
lists
) – Each element is a list in the form of an OSC message or bundle.note (.) –
bundle can be only composed of messages. (generated) –
Notes
Elements lists representing messages or bundles. Invoked as:
addr.send_bundle(1, ['/msg', ...], [1.2, ['/bndl', ...], ...], ...)
-
send_clumped_bundles
(time, *elements)¶ This method is used to send bundles larger than UDP datagram size as successive sub-clumped packages.
-
send_status_msg
()¶ Send ‘/status’ message to the server.
The server will respond with ‘/status.reply’.
-
sync
(condition=None, latency=None, elements=None)¶ Generator method that internally manages server’s ‘/sync’ message. Because it’s used to synchronize bundles sent to the server it is primarly used through Server’s
sync
wrapper method.- Parameters
condition (
Condition
) – An optional instance of Condition that will be used to wait for the reply.latancy (
int | float
) – Bundle’s latency as insend_bundle
.elements (
list
) – A list of lists as OSC messages which will be sent before the ‘/sync’ message.
-
get_bundle
(time=None)¶ Return all bundled messages so far.
-