FoxDot.lib.OSC3

This module contains an OpenSoundControl implementation (in Pure Python), based (somewhat) on the good old ‘SimpleOSC’ implementation by Daniel Holth & Clinton McChesney.

This implementation is intended to still be ‘simple’ to the user, but much more complete (with OSCServer & OSCClient classes) and much more powerful (the OSCMultiClient supports subscriptions & message-filtering, OSCMessage & OSCBundle are now proper container-types)

OpenSoundControl

OpenSoundControl is a network-protocol for sending (small) packets of addressed data over network sockets. This OSC-implementation supports the classical UDP/IP protocol for sending and receiving packets but provides as well support for TCP/IP streaming, whereas the message size is prepended as int32 (big endian) before each message/packet.

OSC-packets come in two kinds:

  • OSC-messages consist of an ‘address’-string (not to be confused with a

(host:port) network-address!), followed by a string of ‘typetags’ associated with the message’s arguments (ie. ‘payload’), and finally the arguments themselves, encoded in an OSC-specific way. The OSCMessage class makes it easy to create & manipulate OSC-messages of this kind in a ‘pythonesque’ way (that is, OSCMessage-objects behave a lot like lists)

  • OSC-bundles are a special type of OSC-message containing only

OSC-messages as ‘payload’. Recursively. (meaning; an OSC-bundle could contain other OSC-bundles, containing OSC-bundles etc.)

OSC-bundles start with the special keyword ‘#bundle’ and do not have an OSC-address (but the OSC-messages a bundle contains will have OSC-addresses!). Also, an OSC-bundle can have a timetag, essentially telling the receiving server to ‘hold’ the bundle until the specified time. The OSCBundle class allows easy cration & manipulation of OSC-bundles.

For further information see also http://opensoundcontrol.org/spec-1_0


To send OSC-messages, you need an OSCClient, and to receive OSC-messages you need an OSCServer.

The OSCClient uses an ‘AF_INET / SOCK_DGRAM’ type socket (see the ‘socket’ module) to send binary representations of OSC-messages to a remote host:port address.

The OSCServer listens on an ‘AF_INET / SOCK_DGRAM’ type socket bound to a local port, and handles incoming requests. Either one-after-the-other (OSCServer) or in a multi-threaded / multi-process fashion (ThreadingOSCServer/ ForkingOSCServer). If the Server has a callback-function (a.k.a. handler) registered to ‘deal with’ (i.e. handle) the received message’s OSC-address, that function is called, passing it the (decoded) message.

The different OSCServers implemented here all support the (recursive) un- bundling of OSC-bundles, and OSC-bundle timetags.

In fact, this implementation supports:

  • OSC-messages with ‘i’ (int32), ‘f’ (float32), ‘d’ (double), ‘s’ (string) and

‘b’ (blob / binary data) types - OSC-bundles, including timetag-support - OSC-address patterns including ‘*’, ‘?’, ‘{,}’ and ‘[]’ wildcards.

(please do read the OSC-spec! http://opensoundcontrol.org/spec-1_0 it explains what these things mean.)

In addition, the OSCMultiClient supports:
  • Sending a specific OSC-message to multiple remote servers

  • Remote server subscription / unsubscription (through OSC-messages, of course)

  • Message-address filtering.

pyOSC:

Copyright (c) 2008-2010, Artem Baguinski <artm@v2.nl> et al., Stock, V2_Lab, Rotterdam, Netherlands.

Streaming support (OSC over TCP):

Copyright (c) 2010 Uli Franke <uli.franke@weiss.ch>, Weiss Engineering, Uster, Switzerland.

Changelog:

v0.3.0 - 27 Dec. 2007

Started out to extend the ‘SimpleOSC’ implementation (v0.2.3) by Daniel Holth & Clinton McChesney. Rewrote OSCMessage Added OSCBundle

v0.3.1 - 3 Jan. 2008

Added OSClient Added OSCRequestHandler, loosely based on the original CallbackManager Added OSCServer Removed original CallbackManager Adapted testing-script (the ‘if __name__ == “__main__”:’ block at the end) to use new Server & Client

v0.3.2 - 5 Jan. 2008

Added ‘container-type emulation’ methods (getitem(), setitem(), __iter__() & friends) to OSCMessage Added ThreadingOSCServer & ForkingOSCServer

  • 6 Jan. 2008

Added OSCMultiClient Added command-line options to testing-script (try ‘python OSC.py –help’)

v0.3.3 - 9 Jan. 2008

Added OSC-timetag support to OSCBundle & OSCRequestHandler Added ThreadingOSCRequestHandler

v0.3.4 - 13 Jan. 2008

Added message-filtering to OSCMultiClient Added subscription-handler to OSCServer Added support fon numpy/scipy int & float types. (these get converted to ‘standard’ 32-bit OSC ints / floats!) Cleaned-up and added more Docstrings

v0.3.5 - 14 aug. 2008

Added OSCServer.reportErr(…) method

v0.3.6 - 19 April 2010

Added Streaming support (OSC over TCP) Updated documentation Moved pattern matching stuff into separate class (OSCAddressSpace) to

facilitate implementation of different server and client architectures. Callbacks feature now a context (object oriented) but dynamic function inspection keeps the code backward compatible

Moved testing code into separate testbench (testbench.py)

Original Comments

> Open SoundControl for Python > Copyright (C) 2002 Daniel Holth, Clinton McChesney > > This library is free software; you can redistribute it and/or modify it under > the terms of the GNU Lesser General Public License as published by the Free > Software Foundation; either version 2.1 of the License, or (at your option) any > later version. > > This library is distributed in the hope that it will be useful, but WITHOUT ANY > WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A > PARTICULAR PURPOSE. See the GNU Lesser General Public License for more > details. > > You should have received a copy of the GNU Lesser General Public License along > with this library; if not, write to the Free Software Foundation, Inc., 59 > Temple Place, Suite 330, Boston, MA 02111-1307 USA > > For questions regarding this module contact Daniel Holth <dholth@stetson.edu> > or visit http://www.stetson.edu/~ProctoLogic/ > > Changelog: > 15 Nov. 2001: > Removed dependency on Python 2.0 features. > - dwh > 13 Feb. 2002: > Added a generic callback handler. > - dwh

class FoxDot.lib.OSC3.ForkingOSCServer(server_address, client=None, return_port=0)[source]

Bases: ForkingMixIn, OSCServer

An Asynchronous OSCServer. This server forks a new process to handle each incoming request.

RequestHandlerClass

alias of ThreadingOSCRequestHandler

exception FoxDot.lib.OSC3.NoCallbackError(pattern)[source]

Bases: OSCServerError

This error is raised (by an OSCServer) when an OSCMessage with an ‘unmatched’ address-pattern is received, and no ‘default’ handler is registered.

exception FoxDot.lib.OSC3.NotSubscribedError(addr, prefix=None)[source]

Bases: OSCClientError

This error is raised (by an OSCMultiClient) when an attempt is made to unsubscribe a host that isn’t subscribed.

class FoxDot.lib.OSC3.OSCAddressSpace[source]

Bases: object

addMsgHandler(address, callback)[source]
Register a handler for an OSC-address
  • ‘address’ is the OSC address-string.

the address-string should start with ‘/’ and may not contain ‘*’
  • ‘callback’ is the function called for incoming OSCMessages that match ‘address’.

The callback-function will be called with the same arguments as the ‘msgPrinter_handler’ below

delMsgHandler(address)[source]

Remove the registered handler for the given OSC-address

dispatchMessage(pattern, tags, data, client_address)[source]

Attmept to match the given OSC-address pattern, which may contain ‘*’, against all callbacks registered with the OSCServer. Calls the matching callback and returns whatever it returns. If no match is found, and a ‘default’ callback is registered, it calls that one, or raises NoCallbackError if a ‘default’ callback is not registered.

  • pattern (string): The OSC-address of the receied message

  • tags (string): The OSC-typetags of the receied message’s arguments, without ‘,’

  • data (list): The message arguments

getOSCAddressSpace()[source]

Returns a list containing all OSC-addresses registerd with this Server.

FoxDot.lib.OSC3.OSCArgument(next, typehint=None)[source]

Convert some Python types to their OSC binary representations, returning a (typetag, data) tuple.

FoxDot.lib.OSC3.OSCBlob(next)[source]

Convert a string into an OSC Blob. An OSC-Blob is a binary encoded block of data, prepended by a ‘size’ (int32). The size is always a mutiple of 4 bytes. The blob ends with 0 to 3 zero-bytes (’')

class FoxDot.lib.OSC3.OSCBundle(address='', time=0)[source]

Bases: OSCMessage

Builds a ‘bundle’ of OSC messages.

OSCBundle objects are container objects for building OSC-bundles of OSC-messages. An OSC-bundle is a special kind of OSC-message which contains a list of OSC-messages (And yes, OSC-bundles may contain other OSC-bundles…)

OSCBundle objects behave much the same as OSCMessage objects, with these exceptions:
  • if an item or items to be appended or inserted are not OSCMessage objects,

OSCMessage objectss are created to encapsulate the item(s) - an OSC-bundle does not have an address of its own, only the contained OSC-messages do. The OSCBundle’s ‘address’ is inherited by any OSCMessage the OSCBundle object creates. - OSC-bundles have a timetag to tell the receiver when the bundle should be processed. The default timetag value (0) means ‘immediately’

append(argument, typehint=None)[source]

Appends data to the bundle, creating an OSCMessage to encapsulate the provided argument unless this is already an OSCMessage. Any newly created OSCMessage inherits the OSCBundle’s address at the time of creation. If ‘argument’ is an iterable, its elements will be encapsuated by a single OSCMessage. Finally, ‘argument’ can be (or contain) a dict, which will be ‘converted’ to an OSCMessage;

  • if ‘addr’ appears in the dict, its value overrides the OSCBundle’s address

  • if ‘args’ appears in the dict, its value(s) become the OSCMessage’s arguments

copy()[source]

Returns a deep copy of this OSCBundle

getBinary()[source]

Returns the binary representation of the message

getTimeTagStr()[source]

Return the TimeTag as a human-readable string

setTimeTag(time)[source]

Set or change the OSCBundle’s TimeTag In ‘Python Time’, that’s floating seconds since the Epoch

values()[source]

Returns a list of the OSCMessages appended so far

class FoxDot.lib.OSC3.OSCClient(server=None)[source]

Bases: object

Simple OSC Client. Handles the sending of OSC-Packets (OSCMessage or OSCBundle) via a UDP-socket

address()[source]

Returns a (host,port) tuple of the remote server this client is connected to or None if not connected to any server.

close()[source]

Disconnect & close the Client’s socket

connect(address)[source]

Bind to a specific OSC server: the ‘address’ argument is a (host, port) tuple

  • host: hostname of the remote OSC server,

  • port: UDP-port the remote OSC server listens to.

send(msg, timeout=None)[source]

Send the given OSCMessage. The Client must be already connected.

  • msg: OSCMessage (or OSCBundle) to be sent

  • timeout: A timeout value for attempting to send. If timeout == None,

    this call blocks until socket is available for writing.

Raises OSCClientError when timing out while waiting for the socket, or when the Client isn’t connected to a remote server.

sendto(msg, address, timeout=None)[source]
Send the given OSCMessage to the specified address.
  • msg: OSCMessage (or OSCBundle) to be sent

  • address: (host, port) tuple specifing remote server to send the message to

  • timeout: A timeout value for attempting to send. If timeout == None,

    this call blocks until socket is available for writing.

Raises OSCClientError when timing out while waiting for the socket.

setServer(server)[source]

Associate this Client with given server. The Client will send from the Server’s socket. The Server will use this Client instance to send replies.

sndbuf_size = 32768
exception FoxDot.lib.OSC3.OSCClientError(message)[source]

Bases: OSCError

Class for all OSCClient errors

exception FoxDot.lib.OSC3.OSCError(message)[source]

Bases: Exception

Base Class for all OSC-related errors

class FoxDot.lib.OSC3.OSCMessage(address='', *args)[source]

Bases: object

Builds typetagged OSC messages.

OSCMessage objects are container objects for building OSC-messages. On the ‘front’ end, they behave much like list-objects, and on the ‘back’ end they generate a binary representation of the message, which can be sent over a network socket. OSC-messages consist of an ‘address’-string (not to be confused with a (host, port) IP-address!), followed by a string of ‘typetags’ associated with the message’s arguments (ie. ‘payload’), and finally the arguments themselves, encoded in an OSC-specific way.

On the Python end, OSCMessage are lists of arguments, prepended by the message’s address. The message contents can be manipulated much like a list:

>>> msg = OSCMessage("/my/osc/address")
>>> msg.append('something')
>>> msg.insert(0, 'something else')
>>> msg[1] = 'entirely'
>>> msg.extend([1,2,3.])
>>> msg += [4, 5, 6.]
>>> del msg[3:6]
>>> msg.pop(-2)
5
>>> print msg
/my/osc/address ['something else', 'entirely', 1, 6.0]

OSCMessages can be concatenated with the + operator. In this case, the resulting OSCMessage inherits its address from the left-hand operand. The right-hand operand’s address is ignored. To construct an ‘OSC-bundle’ from multiple OSCMessage, see OSCBundle!

Additional methods exist for retreiving typetags or manipulating items as (typetag, value) tuples.

append(argument, typehint=None)[source]

Appends data to the message, updating the typetags based on the argument’s type. If the argument is a blob (counted string) pass in ‘b’ as typehint. ‘argument’ may also be a list or tuple, in which case its elements will get appended one-by-one, all using the provided typehint

clear(address='')[source]

Clear (or set a new) OSC-address and clear any arguments appended so far

clearData()[source]

Clear any arguments appended so far

copy()[source]

Returns a deep copy of this OSCMessage

count(val)[source]

Returns the number of times the given value occurs in the OSCMessage’s arguments

extend(values)[source]

Append the contents of ‘values’ to this OSCMessage. ‘values’ can be another OSCMessage, or a list/tuple of ints/floats/strings

getBinary()[source]

Returns the binary representation of the message

index(val)[source]

Returns the index of the first occurence of the given value in the OSCMessage’s arguments. Raises ValueError if val isn’t found

insert(i, val, typehint=None)[source]

Insert given value (with optional typehint) into the OSCMessage at the given index.

items()[source]

Returns a list of (typetag, value) tuples for the arguments appended so far

iteritems()[source]

Returns an iterator of the OSCMessage’s arguments as (typetag, value) tuples

itertags()[source]

Returns an iterator of the OSCMessage’s arguments’ typetags

itervalues()[source]

Returns an iterator of the OSCMessage’s arguments

pop(i)[source]

Delete the indicated argument from the OSCMessage, and return it.

popitem(i)[source]

Delete the indicated argument from the OSCMessage, and return it as a (typetag, value) tuple.

remove(val)[source]

Removes the first argument with the given value from the OSCMessage. Raises ValueError if val isn’t found.

reverse()[source]

Reverses the arguments of the OSCMessage (in place)

setAddress(address)[source]

Set or change the OSC-address

setItem(i, val, typehint=None)[source]

Set indicated argument to a new value (with typehint)

tags()[source]

Returns a list of typetags of the appended arguments

values()[source]

Returns a list of the arguments appended so far

class FoxDot.lib.OSC3.OSCMultiClient(server=None)[source]

Bases: OSCClient

‘Multiple-Unicast’ OSC Client. Handles the sending of OSC-Packets (OSCMessage or OSCBundle) via a UDP-socket This client keeps a dict of ‘OSCTargets’. and sends each OSCMessage to each OSCTarget The OSCTargets are simply (host, port) tuples, and may be associated with an OSC-address prefix. the OSCTarget’s prefix gets prepended to each OSCMessage sent to that target.

clearOSCTargets()[source]

Erases all OSCTargets from the Client’s dict

connect(address)[source]

The OSCMultiClient isn’t allowed to connect to any specific address.

delOSCTarget(address, prefix=None)[source]

Delete the specified OSCTarget from the Client’s dict. the ‘address’ argument can be a ((host, port) tuple), or a hostname. If the ‘prefix’ argument is given, the Target is only deleted if the address and prefix match.

getOSCTarget(address)[source]

Returns the OSCTarget matching the given address as a ((host, port), [prefix, filters]) tuple. ‘address’ can be a (host, port) tuple, or a ‘host’ (string), in which case the first matching OSCTarget is returned Returns (None, [‘’,{}]) if address not found.

getOSCTargetStr(address)[source]

Returns the OSCTarget matching the given address as a (‘osc://<host>:<port>[<prefix>]’, [‘<filter-string>’, …])’ tuple. ‘address’ can be a (host, port) tuple, or a ‘host’ (string), in which case the first matching OSCTarget is returned Returns (None, []) if address not found.

getOSCTargetStrings()[source]

Returns a list of all OSCTargets as (‘osc://<host>:<port>[<prefix>]’, [‘<filter-string>’, …])’ tuples.

getOSCTargets()[source]

Returns the dict of OSCTargets: {addr:[prefix, filters], …}

hasOSCTarget(address, prefix=None)[source]

Return True if the given OSCTarget exists in the Client’s dict. the ‘address’ argument can be a ((host, port) tuple), or a hostname. If the ‘prefix’ argument is given, the return-value is only True if the address and prefix match.

send(msg, timeout=None)[source]
Send the given OSCMessage to all subscribed OSCTargets
  • msg: OSCMessage (or OSCBundle) to be sent

  • timeout: A timeout value for attempting to send. If timeout == None,

    this call blocks until socket is available for writing.

Raises OSCClientError when timing out while waiting for the socket.

sendto(msg, address, timeout=None)[source]

Send the given OSCMessage. The specified address is ignored. Instead this method calls send() to send the message to all subscribed clients.

  • msg: OSCMessage (or OSCBundle) to be sent

  • address: (host, port) tuple specifing remote server to send the message to

  • timeout: A timeout value for attempting to send. If timeout == None,

    this call blocks until socket is available for writing.

Raises OSCClientError when timing out while waiting for the socket.

setOSCTarget(address, prefix=None, filters=None)[source]

Add (i.e. subscribe) a new OSCTarget, or change the prefix for an existing OSCTarget. the ‘address’ argument can be a ((host, port) tuple) : The target server address & UDP-port

or a ‘host’ (string) : The host will be looked-up

  • prefix (string): The OSC-address prefix prepended to the address of each OSCMessage

sent to this OSCTarget (optional)

setOSCTargetFromStr(url)[source]

Adds or modifies a subscribed OSCTarget from the given string, which should be in the ‘<host>:<port>[/<prefix>] [+/<filter>]|[-/<filter>] …’ format.

updateOSCTargets(dict)[source]

Update the Client’s OSCTargets dict with the contents of ‘dict’ The given dict’s items MUST be of the form

{ (host, port):[prefix, filters], … }

class FoxDot.lib.OSC3.OSCRequestHandler(request, client_address, server)[source]

Bases: DatagramRequestHandler

RequestHandler class for the OSCServer

finish()[source]

Finish handling OSCMessage. Send any reply returned by the callback(s) back to the originating client as an OSCMessage or OSCBundle

handle()[source]

Handle incoming OSCMessage

setup()[source]

Prepare RequestHandler. Unpacks request as (packet, source socket address) Creates an empty list for replies.

class FoxDot.lib.OSC3.OSCServer(server_address, client=None, return_port=0)[source]

Bases: UDPServer, OSCAddressSpace

A Synchronous OSCServer Serves one request at-a-time, until the OSCServer is closed. The OSC address-pattern is matched against a set of OSC-adresses that have been registered to the server with a callback-function. If the adress-pattern of the message machtes the registered address of a callback, that function is called.

RequestHandlerClass

alias of OSCRequestHandler

addDefaultHandlers(prefix='', info_prefix='/info', error_prefix='/error')[source]

Register a default set of OSC-address handlers with this Server: - ‘default’ -> noCallback_handler the given prefix is prepended to all other callbacks registered by this method: - ‘<prefix><info_prefix’ -> serverInfo_handler - ‘<prefix><error_prefix> -> msgPrinter_handler - ‘<prefix>/print’ -> msgPrinter_handler and, if the used Client supports it; - ‘<prefix>/subscribe’ -> subscription_handler - ‘<prefix>/unsubscribe’ -> subscription_handler

Note: the given ‘error_prefix’ argument is also set as default ‘error_prefix’ for error-messages sent from this server. This is ok, because error-messages generally do not elicit a reply from the receiver.

To do this with the serverInfo-prefixes would be a bad idea, because if a request received on ‘/info’ (for example) would send replies to ‘/info’, this could potentially cause a never-ending loop of messages! Do not set the ‘info_prefix’ here (for incoming serverinfo requests) to the same value as given to the setSrvInfoPrefix() method (for replies to incoming serverinfo requests). For example, use ‘/info’ for incoming requests, and ‘/inforeply’ or ‘/serverinfo’ or even just ‘/print’ as the info-reply prefix.

address()[source]

Returns a (host,port) tuple of the local address this server is bound to, or None if not bound to any address.

close()[source]

Stops serving requests, closes server (socket), closes used client

handle_error(request, client_address)[source]

Handle an exception in the Server’s callbacks gracefully. Writes the error to sys.stderr and, if the error_prefix (see setSrvErrorPrefix()) is set, sends the error-message as reply to the client

msgPrinter_handler(addr, tags, data, client_address)[source]

Example handler for OSCMessages. All registerd handlers must accept these three arguments: - addr (string): The OSC-address pattern of the received Message

(the ‘addr’ string has already been matched against the handler’s registerd OSC-address, but may contain ‘*’s & such)

  • tags (string): The OSC-typetags of the received message’s arguments. (without the preceding comma)

  • data (list): The OSCMessage’s arguments Note that len(tags) == len(data)

  • client_address ((host, port) tuple): the host & port this message originated from.

a Message-handler function may return None, but it could also return an OSCMessage (or OSCBundle), which then gets sent back to the client.

This handler prints the received message. Returns None

noCallback_handler(addr, tags, data, client_address)[source]

Example handler for OSCMessages. All registerd handlers must accept these three arguments: - addr (string): The OSC-address pattern of the received Message

(the ‘addr’ string has already been matched against the handler’s registerd OSC-address, but may contain ‘*’s & such)

  • tags (string): The OSC-typetags of the received message’s arguments. (without the preceding comma)

  • data (list): The OSCMessage’s arguments Note that len(tags) == len(data)

  • client_address ((host, port) tuple): the host & port this message originated from.

a Message-handler function may return None, but it could also return an OSCMessage (or OSCBundle), which then gets sent back to the client.

This handler prints a “No callback registered to handle …” message. Returns None

printErr(txt)[source]

Writes ‘OSCServer: txt’ to sys.stderr

print_tracebacks = False
reportErr(txt, client_address)[source]

Writes ‘OSCServer: txt’ to sys.stderr If self.error_prefix is defined, sends ‘txt’ as an OSC error-message to the client(s) (see printErr() and sendOSCerror())

sendOSCerror(txt, client_address)[source]

Sends ‘txt’, encapsulated in an OSCMessage to the default ‘error_prefix’ OSC-addres. Message is sent to the given client_address, with the default ‘return_port’ overriding the client_address’ port, if defined.

sendOSCinfo(txt, client_address)[source]

Sends ‘txt’, encapsulated in an OSCMessage to the default ‘info_prefix’ OSC-addres. Message is sent to the given client_address, with the default ‘return_port’ overriding the client_address’ port, if defined.

serve_forever()[source]

Handle one request at a time until server is closed.

serverInfo_handler(addr, tags, data, client_address)[source]

Example handler for OSCMessages. All registerd handlers must accept these three arguments: - addr (string): The OSC-address pattern of the received Message

(the ‘addr’ string has already been matched against the handler’s registerd OSC-address, but may contain ‘*’s & such)

  • tags (string): The OSC-typetags of the received message’s arguments. (without the preceding comma)

  • data (list): The OSCMessage’s arguments Note that len(tags) == len(data)

  • client_address ((host, port) tuple): the host & port this message originated from.

a Message-handler function may return None, but it could also return an OSCMessage (or OSCBundle), which then gets sent back to the client.

This handler returns a reply to the client, which can contain various bits of information about this server, depending on the first argument of the received OSC-message: - ‘help’ | ‘info’ : Reply contains server type & version info, plus a list of

available ‘commands’ understood by this handler

  • ‘list’ | ‘ls’ : Reply is a bundle of ‘address <string>’ messages, listing the server’s OSC address-space.

  • ‘clients’ | ‘targets’ : Reply is a bundle of ‘target osc://<host>:<port>[<prefix>] [<filter>] […]’ messages, listing the local Client-instance’s subscribed remote clients.

setClient(client)[source]

Associate this Server with a new local Client instance, closing the Client this Server is currently using.

setReturnPort(port)[source]

Set the destination UDP-port for replies returning from this server to the remote client

setSrvErrorPrefix(pattern='')[source]

Set the OSC-address (pattern) this server will use to report errors occuring during received message handling to the remote client.

If pattern is empty (default), server-errors are not reported back to the client.

setSrvInfoPrefix(pattern)[source]

Set the first part of OSC-address (pattern) this server will use to reply to server-info requests.

socket_timeout = 1
subscription_handler(addr, tags, data, client_address)[source]

Handle ‘subscribe’ / ‘unsubscribe’ requests from remote hosts, if the local Client supports this (i.e. OSCMultiClient).

Supported commands: - ‘help’ | ‘info’ : Reply contains server type & version info, plus a list of

available ‘commands’ understood by this handler

  • ‘list’ | ‘ls’ : Reply is a bundle of ‘target osc://<host>:<port>[<prefix>] [<filter>] […]’ messages, listing the local Client-instance’s subscribed remote clients.

  • ‘[subscribe | listen | sendto | target] <url> [<filter> …] : Subscribe remote client/server at <url>, and/or set message-filters for messages being sent to the subscribed host, with the optional <filter> arguments. Filters are given as OSC-addresses (or ‘*’) prefixed by a ‘+’ (send matching messages) or a ‘-’ (don’t send matching messages). The wildcard ‘*’, ‘+*’ or ‘+/’ means ‘send all’ / ‘filter none’, and ‘-’ or ‘-/*’ means ‘send none’ / ‘filter all’ (which is not the same as unsubscribing!) Reply is an OSCMessage with the (new) subscription; ‘target osc://<host>:<port>[<prefix>] [<filter>] […]’

  • ‘[unsubscribe | silence | nosend | deltarget] <url> : Unsubscribe remote client/server at <url> If the given <url> isn’t subscribed, a NotSubscribedError-message is printed (and possibly sent)

The <url> given to the subscribe/unsubscribe handler should be of the form: ‘[osc://][<host>][:<port>][<prefix>]’, where any or all components can be omitted.

If <host> is not specified, the IP-address of the message’s source is used. If <port> is not specified, the <host> is first looked up in the list of subscribed hosts, and if found, the associated port is used. If <port> is not specified and <host> is not yet subscribed, the message’s source-port is used. If <prefix> is specified on subscription, <prefix> is prepended to the OSC-address of all messages sent to the subscribed host. If <prefix> is specified on unsubscription, the subscribed host is only unsubscribed if the host, port and prefix all match the subscription. If <prefix> is not specified on unsubscription, the subscribed host is unsubscribed if the host and port match the subscription.

exception FoxDot.lib.OSC3.OSCServerError(message)[source]

Bases: OSCError

Class for all OSCServer errors

class FoxDot.lib.OSC3.OSCStreamRequestHandler(request, client_address, server)[source]

Bases: StreamRequestHandler, OSCAddressSpace

This is the central class of a streaming OSC server. If a client connects to the server, the server instantiates a OSCStreamRequestHandler for each new connection. This is fundamentally different to a packet oriented server which has a single address space for all connections. This connection based (streaming) OSC server maintains an address space for each single connection, because usually tcp server spawn a new thread or process for each new connection. This would generate severe multithreading synchronization problems when each thread would operate on the same address space object. Therefore: To implement a streaming/TCP OSC server a custom handler must be implemented which implements the setupAddressSpace member in which it creates its own address space for this very connection. This has been done within the testbench and can serve as inspiration.

finish()[source]
handle()[source]

Handle a connection.

sendOSC(oscData)[source]

This member can be used to transmit OSC messages or OSC bundles over the client/server connection. It is thread save.

setup()[source]
setupAddressSpace()[source]

Override this function to customize your address space.

class FoxDot.lib.OSC3.OSCStreamingClient[source]

Bases: OSCAddressSpace

OSC streaming client. A streaming client establishes a connection to a streaming server but must be able to handle replies by the server as well. To accomplish this the receiving takes place in a secondary thread, because no one knows if we have to expect a reply or not, i.e. synchronous architecture doesn’t make much sense. Replies will be matched against the local address space. If message handlers access code of the main thread (where the client messages are sent to the server) care must be taken e.g. by installing sychronization mechanisms or by using an event dispatcher which can handle events originating from other threads.

close()[source]
connect(address)[source]
rcvbuf_size = 32768
sendOSC(msg)[source]

Send an OSC message or bundle to the server. Returns True on success.

sndbuf_size = 32768
class FoxDot.lib.OSC3.OSCStreamingServer(address)[source]

Bases: TCPServer

A connection oriented (TCP/IP) OSC server.

RequestHandlerClass

alias of OSCStreamRequestHandler

broadcastToClients(oscData)[source]

Send OSC message or bundle to all connected clients.

serve_forever()[source]

Handle one request at a time until server is closed. Had to add this since 2.5 does not support server.shutdown()

socket_timeout = 1
start()[source]

Start the server thread.

stop()[source]

Stop the server thread and close the socket.

class FoxDot.lib.OSC3.OSCStreamingServerThreading(address)[source]

Bases: ThreadingMixIn, OSCStreamingServer

FoxDot.lib.OSC3.OSCString(next)[source]

Convert a string into a zero-padded OSC String. The length of the resulting string is always a multiple of 4 bytes. The string ends with 1 to 4 zero-bytes (’')

FoxDot.lib.OSC3.OSCTimeTag(time)[source]

Convert a time in floating seconds to its OSC binary representation

class FoxDot.lib.OSC3.ThreadingOSCRequestHandler(request, client_address, server)[source]

Bases: OSCRequestHandler

Multi-threaded OSCRequestHandler; Starts a new RequestHandler thread for each unbundled OSCMessage

class FoxDot.lib.OSC3.ThreadingOSCServer(server_address, client=None, return_port=0)[source]

Bases: ThreadingMixIn, OSCServer

An Asynchronous OSCServer. This server starts a new thread to handle each incoming request.

RequestHandlerClass

alias of ThreadingOSCRequestHandler

FoxDot.lib.OSC3.decodeOSC(data)[source]

Converts a binary OSC message to a Python list.

FoxDot.lib.OSC3.getFilterStr(filters)[source]

Return the given ‘filters’ dict as a list of ‘+<addr>’ | ‘-<addr>’ filter-strings

FoxDot.lib.OSC3.getRegEx(pattern)[source]

Compiles and returns a ‘regular expression’ object for the given address-pattern.

FoxDot.lib.OSC3.getUrlStr(*args)[source]

Convert provided arguments to a string in ‘host:port/prefix’ format Args can be:

  • (host, port)

  • (host, port), prefix

  • host, port

  • host, port, prefix

FoxDot.lib.OSC3.hexDump(bytes)[source]

Useful utility; prints the string in hexadecimal.

FoxDot.lib.OSC3.parseFilterStr(args)[source]

Convert Message-Filter settings in ‘+<addr> -<addr> …’ format to a dict of the form { ‘<addr>’:True, ‘<addr>’:False, … } Returns a list: [‘<prefix>’, filters]

FoxDot.lib.OSC3.parseUrlStr(url)[source]

Convert provided string in ‘host:port/prefix’ format to it’s components Returns ((host, port), prefix)

FoxDot.lib.OSC3.version = ('0.3', '6', '6382')

Built-in immutable sequence.

If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.

If the argument is a tuple, the return value is the same object.

FoxDot.lib.OSC3.FloatTypes = [<class 'float'>]

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

FoxDot.lib.OSC3.IntTypes = [<class 'int'>]

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

FoxDot.lib.OSC3.NTP_epoch = -2208988800

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral. >>> int(‘0b100’, base=0) 4

FoxDot.lib.OSC3.NTP_units_per_second = 4294967296

int([x]) -> integer int(x, base=10) -> integer

Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.__int__(). For floating-point numbers, this truncates towards zero.

If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by ‘+’ or ‘-’ and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral. >>> int(‘0b100’, base=0) 4

FoxDot.lib.OSC3.OSCtrans = {44: 124, 63: 46, 123: 40, 125: 41}

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)