-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbackend.py
41 lines (32 loc) · 1.15 KB
/
backend.py
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
from __future__ import division
from platform import system, release
from os import environ
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner
class Component(ApplicationSession):
"""
An application component providing procedures with different kinds
of arguments.
"""
@inlineCallbacks
def onJoin(self, details):
print("session attached")
def on_topic(title):
print("Got event: {}".format(title))
def platform():
print "backend platform()"
return [system(), release()]
def divide(a, b):
print "backend divide()"
return a / b
yield self.subscribe(on_topic, u'com.myapp.topic')
yield self.register(platform, u'com.myapp.platform')
yield self.register(divide, u'com.myapp.divide')
print("Procedures registered; ready for frontend.")
if __name__ == '__main__':
router_address = environ.get("ROUTER_ADDRESS", u"ws://127.0.0.1:8080/ws")
runner = ApplicationRunner(
unicode(router_address),
u"realm1",
)
runner.run(Component)