File: backend.py

package info (click to toggle)
python-autobahn 22.7.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,404 kB
  • sloc: python: 38,356; javascript: 2,705; makefile: 905; ansic: 371; sh: 63
file content (54 lines) | stat: -rw-r--r-- 1,163 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


from autobahn.asyncio.component import Component, run
from autobahn.wamp.types import RegisterOptions

import asyncio
import ssl


context = ssl.create_default_context(
    purpose=ssl.Purpose.SERVER_AUTH,
    cafile='../../../router/.crossbar/server.crt',
)
component = Component(
    transports=[
        {
            "type": "websocket",
            "url": "wss://localhost:8083/ws",
            "endpoint": {
                "type": "tcp",
                "host": "localhost",
                "port": 8083,
                "tls": context,
            },
            "options": {
                "open_handshake_timeout": 100,
            }
        },
    ],
    realm="crossbardemo",
)


@component.on_join
def join(session, details):
    print("joined {}".format(details))


@component.register(
    "example.foo",
    options=RegisterOptions(details_arg='details'),
)
@asyncio.coroutine
def foo(*args, **kw):
    print("foo({}, {})".format(args, kw))
    for x in range(5, 0, -1):
        print("  returning in {}".format(x))
        yield from asyncio.sleep(1)
    print("returning '42'")
    return 42


if __name__ == "__main__":
    run([component])