File: test_newapi8.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 (36 lines) | stat: -rw-r--r-- 1,077 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
29
30
31
32
33
34
35
36
from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks as coroutine
from autobahn.twisted.wamp import Connection

# A single session joins a first realm, leaves and joins another realm
# all over the same, still running transport

@coroutine
def main(transport):
    session = ApplicationSession()

    # join a first realm and do something
    yield session.join(transport, 'myrealm1')
    result = yield session.call('com.myapp.add2', 2, 3)
    print("Result: {}".format(result))

    # leave the realm. the transport will NOT be closed!
    yield session.leave()

    # join a different realm and do something
    yield session.join(transport, 'myrealm2')
    result = yield session.call('com.foobar.mul2', 2, 3)
    print("Result: {}".format(result))

    # leave the realm. the transport will NOT be closed!
    yield session.leave()

    # now close the transport. after this, the transport cannot
    # be reused!
    yield transport.close()



if __name__ == '__main__':
    connection = Connection(main)
    react(connection.start)