File: test_newapi_short.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 (28 lines) | stat: -rw-r--r-- 832 bytes parent folder | download | duplicates (2)
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
from twisted.internet.defer import inlineCallbacks as coroutine
from autobahn.twisted import Client


@coroutine
def on_join(session):
    try:
        res = yield session.call('com.example.add2', 2, 3)
        print("Result: {}".format(res))
    except Exception as e:
        print("Error: {}".format(e))
    finally:
        session.leave()


if __name__ == '__main__':
    # this is Client, a high-level API above Connection and Session
    # it's a what is nowerdays ApplicationRunner, but with a better
    # name and a listener based interface
    client = Client()

    # "on_join" is a Session event that bubbled up via Connection
    # to Client here. this works since Connection/Session have default
    # implementations that by using WAMP defaults
    client.on_join(on_join)

    # now make it run ..
    client.run()