How to use the oscpy.server.OSCThreadServer function in oscpy

To help you get started, we’ve selected a few oscpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kivy / oscpy / tests / test_server.py View on Github external
def test_bind_multi():
    osc = OSCThreadServer()
    sock1 = osc.listen()
    port1 = sock1.getsockname()[1]

    sock2 = osc.listen()
    port2 = sock2.getsockname()[1]
    cont = []

    def success1(*values):
        cont.append(True)

    def success2(*values):
        cont.append(False)

    osc.bind(b'/success', success1, sock1)
    osc.bind(b'/success', success2, sock2)
github kivy / oscpy / tests / test_server.py View on Github external
def test_reuse_callback():
    osc = OSCThreadServer()
    sock = osc.listen()
    port = sock.getsockname()[1]
    cont = []

    def success(*values):
        cont.append(True)

    osc.bind(b'/success', success, sock)
    osc.bind(b'/success', success, sock)
    osc.bind(b'/success2', success, sock)
    assert len(osc.addresses.get((sock, b'/success'))) == 1
    assert len(osc.addresses.get((sock, b'/success2'))) == 1
github kivy / oscpy / tests / test_server.py View on Github external
def test_bind_address():
    osc = OSCThreadServer()
    osc.listen(default=True)
    result = []

    @osc.address(b'/test')
    def success(*args):
        result.append(True)

    timeout = time() + 1

    send_message(b'/test', [], *osc.getaddress())

    while len(result) < 1:
        if time() > timeout:
            raise OSError('timeout while waiting for success message.')
        sleep(10e-9)
github kivy / oscpy / tests / test_server.py View on Github external
def test_send_message_without_socket():
    osc = OSCThreadServer()
    with pytest.raises(RuntimeError):
        osc.send_message(b'/test', [], 'localhost', 0)
github kivy / oscpy / tests / test_server.py View on Github external
def test_socket_family():
    osc = OSCThreadServer()
    assert osc.listen().family == socket.AF_INET
    filename = mktemp()
    if platform != 'win32':
        assert osc.listen(address=filename, family='unix').family == socket.AF_UNIX  # noqa

    else:
        with pytest.raises(NameError) as e_info:
            osc.listen(address=filename, family='unix')

    if exists(filename):
        unlink(filename)

    with pytest.raises(ValueError) as e_info:  # noqa
        osc.listen(family='')
github kivy / oscpy / tests / test_server.py View on Github external
osc_1 = OSCThreadServer()
    osc_1.listen(default=True)

    @osc_1.address(b'/ping')
    def ping(*values):
        print("ping called")
        if True in values:
            cont.append(True)
        else:
            osc_1.answer(
                bundle=[
                    (b'/pong', [])
                ]
            )

    osc_2 = OSCThreadServer()
    osc_2.listen(default=True)

    @osc_2.address(b'/pong')
    def pong(*values):
        print("pong called")
        osc_2.answer(b'/ping', [True])

    osc_2.send_message(b'/ping', [], *osc_1.getaddress())

    with pytest.raises(RuntimeError) as e_info:  # noqa
        osc_1.answer(b'/bing', [])

    timeout = time() + 2
    while not cont:
        if time() > timeout:
            raise OSError('timeout while waiting for success message.')
github kivy / oscpy / tests / test_client.py View on Github external
def test_send_bundle_safer():
    osc = OSCThreadServer()
    sock = osc.listen()
    port = sock.getsockname()[1]
    acc = []

    def success(*values):
        acc.append(values[0])

    osc.bind(b'/success', success, sock)

    timeout = time() + 5
    while len(acc) < 100:
        if time() > timeout:
            raise OSError('timeout while waiting for  success message.')

        send_bundle(
            [
github kivy / oscpy / tests / test_server.py View on Github external
def test_encoding_send_receive():
    osc = OSCThreadServer(encoding='utf8')
    osc.listen(default=True)

    values = []

    @osc.address(u'/encoded')
    def encoded(*val):
        for v in val:
            assert not isinstance(v, bytes)
        values.append(val)

    send_message(
        u'/encoded',
        ['hello world', u'ééééé ààààà'],
        *osc.getaddress(), encoding='utf8')

    timeout = time() + 2
github AndreMiras / EtherollApp / src / etherollapp / osc / osc_app_server.py View on Github external
"""
The OSC app server makes it possible to communicate with the application from
another process.
OscAppServer -> App
"""
from time import sleep

from oscpy.server import OSCThreadServer, ServerClass

osc = OSCThreadServer()


@ServerClass
class OscAppServer:
    """OSC server used to update the app process."""

    _osc_server = None

    def __init__(self, app=None):
        """app: instance of the application to talk to"""
        self.app = app

    @classmethod
    def get_or_create(cls, app=None):
        """
        Creates the OSC server and binds the app to it.
github kivy / oscpy / oscpy / cli.py View on Github external
def __dump(options):
    def dump(address, *values):
        print(u'{}: {}'.format(
            address.decode('utf8'),
            ', '.join(
                '{}'.format(
                    v.decode(options.encoding or 'utf8')
                    if isinstance(v, bytes)
                    else v
                )
                for v in values if values
            )
        ))

    osc = OSCThreadServer(
        encoding=options.encoding,
        encoding_errors=options.encoding_errors,
        default_handler=dump
    )
    osc.listen(
        address=options.host,
        port=options.port,
        default=True
    )
    return osc