How to use the oscpy.client.send_message 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_cli.py View on Github external
def test___dump(capsys):
    options = Mock()
    options.repeat = 2
    options.host = 'localhost'
    options.port = randint(60000, 65535)
    options.address = b'/test'
    options.safer = False
    options.encoding = None
    options.encoding_errors = 'strict'
    options.message = (1, 2, 3, 4, b"hello world")

    osc = __dump(options)
    out = capsys.readouterr().out
    assert out == ''

    send_message(
        options.address,
        options.message,
        options.host,
        options.port,
        safer=options.safer,
        encoding=options.encoding,
        encoding_errors=options.encoding_errors
    )

    sleep(0.1)
    out, err = capsys.readouterr()
    assert err == ''
    lines = out.split('\n')
    assert lines[0] == u"/test: 1, 2, 3, 4, hello world"

    osc.stop()
github kivy / oscpy / tests / test_server.py View on Github external
def test_encoding_send():
    osc = OSCThreadServer()
    osc.listen(default=True)

    values = []

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

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

    timeout = time() + 2
    while not values:
        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_bind_default():
    osc = OSCThreadServer()
    osc.listen(default=True)
    port = osc.getaddress()[1]
    cont = []

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

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

    send_message(b'/success', [b'test', 1, 1.12345], 'localhost', port)

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

    def success(address, *values):
        assert address == b'/success'
        cont.append(True)

    osc.bind(b'/success', success, sock, get_address=True)

    send_message(b'/success', [b'test', 1, 1.12345], 'localhost', port)

    timeout = time() + 5
    while not cont:
        if time() > timeout:
            raise OSError('timeout while waiting for success message.')
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
    while not values:
        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
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)

    send_message(b'/success', [b'test', 1, 1.12345], 'localhost', port1)
    send_message(b'/success', [b'test', 1, 1.12345], 'localhost', port2)

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

    assert True in cont and False in cont
github kivy / oscpy / tests / test_client.py View on Github external
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_message(b'/success', [1], 'localhost', port)
github kivy / oscpy / tests / test_server.py View on Github external
def test_encoding_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(
        b'/encoded',
        [
            b'hello world',
            u'ééééé ààààà'.encode('utf8')
        ],
        *osc.getaddress())

    timeout = time() + 2
    while not values:
        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_bind():
    osc = OSCThreadServer()
    sock = osc.listen()
    port = sock.getsockname()[1]
    cont = []

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

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

    send_message(b'/success', [b'test', 1, 1.12345], 'localhost', port)

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

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

    osc.bind(b'/failure', failure, sock)
    with pytest.raises(RuntimeError) as e_info:  # noqa
        osc.unbind(b'/failure', failure)
    osc.unbind(b'/failure', failure, sock)

    send_message(b'/failure', [b'test', 1, 1.12345], 'localhost', port)

    timeout = time() + 1
    while time() > timeout:
        assert not cont
        sleep(10e-9)