1###############################################################################
2#
3# The MIT License (MIT)
4#
5# Copyright (c) Crossbar.io Technologies GmbH
6#
7# Permission is hereby granted, free of charge, to any person obtaining a copy
8# of this software and associated documentation files (the "Software"), to deal
9# in the Software without restriction, including without limitation the rights
10# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11# copies of the Software, and to permit persons to whom the Software is
12# furnished to do so, subject to the following conditions:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
17# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23# THE SOFTWARE.
24#
25###############################################################################
26
27from twisted.internet import reactor
28from twisted.internet.defer import inlineCallbacks
29
30from autobahn.twisted.wamp import ApplicationSession
31
32
33
34class Component(ApplicationSession):
35   """
36   An application component calling the different backend procedures.
37   """
38
39   @inlineCallbacks
40   def onJoin(self, details):
41      print("session attached")
42
43      yield self.call(u'com.arguments.ping')
44      print("Pinged!")
45
46      res = yield self.call(u'com.arguments.add2', 2, 3)
47      print("Add2: {}".format(res))
48
49      starred = yield self.call(u'com.arguments.stars')
50      print("Starred 1: {}".format(starred))
51
52      starred = yield self.call(u'com.arguments.stars', nick = u'Homer')
53      print("Starred 2: {}".format(starred))
54
55      starred = yield self.call(u'com.arguments.stars', stars = 5)
56      print("Starred 3: {}".format(starred))
57
58      starred = yield self.call(u'com.arguments.stars', nick = u'Homer', stars = 5)
59      print("Starred 4: {}".format(starred))
60
61      orders = yield self.call(u'com.arguments.orders', u'coffee')
62      print("Orders 1: {}".format(orders))
63
64      orders = yield self.call(u'com.arguments.orders', u'coffee', limit = 10)
65      print("Orders 2: {}".format(orders))
66
67      arglengths = yield self.call(u'com.arguments.arglen')
68      print("Arglen 1: {}".format(arglengths))
69
70      arglengths = yield self.call(u'com.arguments.arglen', 1, 2, 3)
71      print("Arglen 2: {}".format(arglengths))
72
73      arglengths = yield self.call(u'com.arguments.arglen', a = 1, b = 2, c = 3)
74      print("Arglen 3: {}".format(arglengths))
75
76      arglengths = yield self.call(u'com.arguments.arglen', 1, 2, 3, a = 1, b = 2, c = 3)
77      print("Arglen 4: {}".format(arglengths))
78
79      self.leave()
80
81
82   def onDisconnect(self):
83      print("disconnected")
84      reactor.stop()
85
86
87
88if __name__ == '__main__':
89   from autobahn.twisted.wamp import ApplicationRunner
90   runner = ApplicationRunner("ws://127.0.0.1:8080/ws", "realm1")
91   runner.run(Component)
92