transport Module

BaseServer Class

class oscpython.transport.BaseServer(listen_address: Optional[oscpython.common.Client] = None, address_space: Optional[oscpython.address.AddressSpace] = None)[source]

Bases: object

Base server class

Parameters
default_listen_address: ClassVar[oscpython.common.Client] = Client(address='0.0.0.0', port=9000)

Default value for listen_address

listen_address: oscpython.common.Client

The address and port to bind the server to

running: bool

True if the server is running

rx_queue: asyncio.queues.Queue

A Queue for incoming data as QueueItem instances

tx_queue: asyncio.queues.Queue

A Queue for outgoing data as QueueItem instances

property address_space

The AddressSpace associated with the server

property message_handler

The MessageHandler for the server

async send_packet(packet: oscpython.messages.Packet)[source]

Send either a Message or Bundle

The remote_client in the given packet is used as the destination host address and port.

Parameters

packet – The packet to send

async open()[source]

Open the server connections and start all background tasks

Calls open_endpoint() and creates tasks for tx_loop() and rx_loop().

async close()[source]

Stop all background tasks and close all connections

Calls close_endpoint() and stops the tx_loop() and rx_loop() tasks.

async tx_loop()[source]

Wait for items on tx_queue and send them using send_queue_item()

This runs as long as running is True and the task for it is managed by the open() and close() methods

async rx_loop()[source]

Wait for items on rx_queue and pass them to message_handler using MessageHandler.handle_packet().

This runs as long as running is True and the task for it is managed by the open() and close() methods

async open_endpoint()[source]

Open implementation-specific items for communication

Called from the open() method

async close_endpoint()[source]

Close any implementation-specific communication items

Called from the close() method

async send_queue_item(item: oscpython.transport.QueueItem)bool[source]

Handle transmission of a QueueItem's bytestring

Returns

True if the item was sent

Return type

bool

DatagramServer Class

class oscpython.transport.DatagramServer(listen_address: Optional[oscpython.common.Client] = None, address_space: Optional[oscpython.address.AddressSpace] = None)[source]

Bases: oscpython.transport.BaseServer

An OSC Client/Server using UDP

transport: Optional[asyncio.transports.DatagramTransport]

Datagram transport created by create_datagram_endpoint()

protocol: Optional[oscpython.transport.DatagramProtocol]

Protocol created by create_datagram_endpoint()

async open_endpoint()[source]

Open implementation-specific items for communication

Called from the open() method

async close_endpoint()[source]

Close any implementation-specific communication items

Called from the close() method

async send_queue_item(item: oscpython.transport.QueueItem)bool[source]

Handle transmission of a QueueItem's bytestring

Returns

True if the item was sent

Return type

bool

DatagramProtocol Class

class oscpython.transport.DatagramProtocol(rx_queue: asyncio.queues.Queue)[source]

Bases: asyncio.protocols.DatagramProtocol

Asyncio Protocol for datagram communication

rx_queue: asyncio.queues.Queue

The parent server’s rx_queue

connection_made(transport)[source]

Called when a connection is made.

The argument is the transport representing the pipe connection. To receive data, wait for data_received() calls. When the connection is closed, connection_lost() is called.

datagram_received(data: bytes, addr: Tuple[str, int])[source]

Place the incoming data on the rx_queue

MessageHandler Class

class oscpython.transport.MessageHandler(address_space: oscpython.address.AddressSpace)[source]

Bases: object

Handles dispatching packets to an AddressSpace

This is instanciated and managed by BaseServer

Parameters

address_space – The value for address_space

address_space: oscpython.address.AddressSpace

The AddressSpace for the handler

queued_bundles: asyncio.queues.PriorityQueue

A queue for QueuedBundle items whose bundle_timetag is in the future

running: bool

True if the handler is running

async open()[source]

Start background tasks needed for queue management

async close()[source]

Stop dispatching and exit all background tasks

async handle_packet(packet: oscpython.messages.Packet, timetag: oscpython.common.TimeTag)[source]

Handle an incoming Packet

If the packet is a Message, the address_space is searched for any matching nodes and the dispatch() method will be called.

If the packet is a Bundle, this method will be called recursively for all of the packets contained in the bundle.

Parameters
  • packet – A Message or Bundle received from the network

  • timetag – Timestamp of when the data was received. This is the timetag attribute of the QueueItem containing the packet data, not the timetag of the packet itself

async dispatch_loop()[source]

Consume from queued_bundles and dispatch them according to their timetags

This runs as long as running is True and the asyncio.Task for it is managed by the open() and close() methods.

QueueItem Class

class oscpython.transport.QueueItem(data: bytes, addr: Tuple[str, int], timetag: oscpython.common.TimeTag = <factory>)[source]

Bases: object

Item used in BaseServer.rx_queue and BaseServer.tx_queue

data: bytes

The incoming or outgoing data

addr: Tuple[str, int]

The remote address as a tuple of (host, port)

timetag: oscpython.common.TimeTag

Timestamp of when the item was created

For incoming data, this indicates the time of reception

QueuedBundle Class

class oscpython.transport.QueuedBundle(bundle_timetag: oscpython.common.TimeTag, rx_timetag: Optional[oscpython.common.TimeTag], bundle: Optional[oscpython.messages.Bundle])[source]

Bases: object

Item to store bundles in a asyncio.PriorityQueue sorted by bundle_timetag

bundle_timetag: oscpython.common.TimeTag

The timetag value of the bundle. This is duplicated solely for sorting purposes

rx_timetag: Optional[oscpython.common.TimeTag]

The timestamp of when the bundle was received

bundle: Optional[oscpython.messages.Bundle]

The Bundle instance