File: test_newapi_short.py

package info (click to toggle)
python-autobahn 0.14.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,132 kB
  • ctags: 3,069
  • sloc: python: 18,460; makefile: 285; sh: 3
file content (28 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (3)
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(u'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()