diff --git a/autobahn/autobahn/wamp/protocol.py b/autobahn/autobahn/wamp/protocol.py index 5b849919..c9e7ad79 100644 --- a/autobahn/autobahn/wamp/protocol.py +++ b/autobahn/autobahn/wamp/protocol.py @@ -321,14 +321,14 @@ class ApplicationSession(BaseSession): """ Implements :func:`autobahn.wamp.interfaces.ISession.onConnect` """ - self.join(six.u(self.config.realm)) + self.join(self.config.realm) def join(self, realm): """ Implements :func:`autobahn.wamp.interfaces.ISession.join` """ - if True or six.PY2 and type(realm) == str: + if six.PY2 and type(realm) == str: realm = six.u(realm) if self._session_id: diff --git a/autobahn/autobahn/wamp/types.py b/autobahn/autobahn/wamp/types.py index 2472def5..0760c201 100644 --- a/autobahn/autobahn/wamp/types.py +++ b/autobahn/autobahn/wamp/types.py @@ -23,7 +23,10 @@ import six class ComponentConfig: def __init__(self, realm = None, extra = None): - self.realm = six.u(realm) + if six.PY2 and type(realm) == str: + self.realm = six.u(realm) + else: + self.realm = realm self.extra = extra @@ -125,7 +128,9 @@ class SubscribeOptions: assert(details_arg is None or type(details_arg) == str) self.details_arg = details_arg - self.options = {'match': six.u(match)} + if match and six.PY2 and type(match) == str: + match = six.u(match) + self.options = {'match': match} @@ -207,7 +212,6 @@ class RegisterOptions: in this keyword argument to the callable. :type details_arg: str """ - assert(details_arg is None or type(details_arg) == six.text_type) self.details_arg = details_arg self.options = { 'pkeys': pkeys, diff --git a/examples/asyncio/wamp/basic/client.py b/examples/asyncio/wamp/basic/client.py index f8cd6ddb..56d22094 100644 --- a/examples/asyncio/wamp/basic/client.py +++ b/examples/asyncio/wamp/basic/client.py @@ -32,6 +32,9 @@ if __name__ == '__main__': parser.add_argument("-c", "--component", type = str, help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'") + parser.add_argument("-r", "--realm", type = str, default = "realm1", + help = "The WAMP realm to start the component in (if any).") + parser.add_argument("--host", type = str, default = "127.0.0.1", help = 'IP or hostname to connect to.') @@ -51,7 +54,7 @@ if __name__ == '__main__': ## from autobahn.asyncio.wamp import ApplicationSessionFactory from autobahn.wamp import types - session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = u"realm1")) + session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = args.realm)) ## dynamically load the application component .. diff --git a/examples/asyncio/wamp/basic/rpc/slowsquare/frontend.py b/examples/asyncio/wamp/basic/rpc/slowsquare/frontend.py index 7e712206..e6e97aac 100644 --- a/examples/asyncio/wamp/basic/rpc/slowsquare/frontend.py +++ b/examples/asyncio/wamp/basic/rpc/slowsquare/frontend.py @@ -38,7 +38,7 @@ class Component(ApplicationSession): print("{}: {} in {}".format(msg, res, duration)) t1 = time.clock() - d1 = self.call('com.math.slowsquare', 3) + d1 = self.call('com.math.slowsquare', 3, 2) d1.add_done_callback(partial(got, t1, "Slow Square")) t2 = time.clock() diff --git a/examples/asyncio/wamp/basic/server.py b/examples/asyncio/wamp/basic/server.py index 5238e8f6..cce3e282 100644 --- a/examples/asyncio/wamp/basic/server.py +++ b/examples/asyncio/wamp/basic/server.py @@ -32,6 +32,9 @@ if __name__ == '__main__': parser.add_argument("-c", "--component", type = str, default = None, help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.") + parser.add_argument("-r", "--realm", type = str, default = "realm1", + help = "The WAMP realm to start the component in (if any).") + parser.add_argument("--interface", type = str, default = "127.0.0.1", help = 'IP of interface to listen on.') @@ -71,7 +74,7 @@ if __name__ == '__main__': ## run next to the router ## from autobahn.wamp import types - session_factory.add(SessionKlass(types.ComponentConfig(realm = u"realm1"))) + session_factory.add(SessionKlass(types.ComponentConfig(realm = args.realm))) if args.transport == "websocket": diff --git a/examples/twisted/wamp/basic/client.py b/examples/twisted/wamp/basic/client.py index 9f697c74..f629d0d8 100644 --- a/examples/twisted/wamp/basic/client.py +++ b/examples/twisted/wamp/basic/client.py @@ -35,6 +35,9 @@ if __name__ == '__main__': parser.add_argument("-c", "--component", type = str, help = "Start WAMP client with this application component, e.g. 'timeservice.TimeServiceFrontend'") + parser.add_argument("-r", "--realm", type = str, default = "realm1", + help = "The WAMP realm to start the component in (if any).") + parser.add_argument("--endpoint", type = str, default = "tcp:127.0.0.1:8080", help = 'Twisted client endpoint descriptor, e.g. "tcp:127.0.0.1:8080" or "unix:/tmp/mywebsocket".') @@ -64,7 +67,8 @@ if __name__ == '__main__': ## create a WAMP application session factory ## from autobahn.twisted.wamp import ApplicationSessionFactory - session_factory = ApplicationSessionFactory() + from autobahn.wamp import types + session_factory = ApplicationSessionFactory(types.ComponentConfig(realm = args.realm)) ## dynamically load the application component .. diff --git a/examples/twisted/wamp/basic/pubsub/basic/backend.py b/examples/twisted/wamp/basic/pubsub/basic/backend.py index 0029cb3b..b0f3cb09 100644 --- a/examples/twisted/wamp/basic/pubsub/basic/backend.py +++ b/examples/twisted/wamp/basic/pubsub/basic/backend.py @@ -29,15 +29,6 @@ class Component(ApplicationSession): An application component that publishes an event every second. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): counter = 0 diff --git a/examples/twisted/wamp/basic/pubsub/basic/frontend.py b/examples/twisted/wamp/basic/pubsub/basic/frontend.py index 8bc7e333..d7d14068 100644 --- a/examples/twisted/wamp/basic/pubsub/basic/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/basic/frontend.py @@ -29,10 +29,6 @@ class Component(ApplicationSession): and stop after having received 5 events. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -47,9 +43,5 @@ class Component(ApplicationSession): yield self.subscribe(on_event, 'com.myapp.topic1') - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/pubsub/complex/backend.py b/examples/twisted/wamp/basic/pubsub/complex/backend.py index 11caff47..6f003738 100644 --- a/examples/twisted/wamp/basic/pubsub/complex/backend.py +++ b/examples/twisted/wamp/basic/pubsub/complex/backend.py @@ -33,15 +33,6 @@ class Component(ApplicationSession): and with complex payloads every second. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): diff --git a/examples/twisted/wamp/basic/pubsub/complex/frontend.py b/examples/twisted/wamp/basic/pubsub/complex/frontend.py index f42e769d..04ff3490 100644 --- a/examples/twisted/wamp/basic/pubsub/complex/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/complex/frontend.py @@ -33,10 +33,6 @@ class Component(ApplicationSession): of no payload and of complex payload, and stops after 5 seconds. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -57,9 +53,5 @@ class Component(ApplicationSession): reactor.callLater(5, self.leave) - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/pubsub/decorators/backend.py b/examples/twisted/wamp/basic/pubsub/decorators/backend.py index fc854d03..457be453 100644 --- a/examples/twisted/wamp/basic/pubsub/decorators/backend.py +++ b/examples/twisted/wamp/basic/pubsub/decorators/backend.py @@ -29,15 +29,6 @@ class Component(ApplicationSession): An application component that publishes an event every second. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): counter = 0 diff --git a/examples/twisted/wamp/basic/pubsub/decorators/frontend.py b/examples/twisted/wamp/basic/pubsub/decorators/frontend.py index 79b0f702..38554499 100644 --- a/examples/twisted/wamp/basic/pubsub/decorators/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/decorators/frontend.py @@ -30,16 +30,6 @@ class Component(ApplicationSession): and stop after having received 5 events. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - self.received = 0 - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): @@ -69,9 +59,5 @@ class Component(ApplicationSession): print("Got event on topic2: {}".format(msg)) - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/pubsub/options/backend.py b/examples/twisted/wamp/basic/pubsub/options/backend.py index cd9ed6ac..0dec5917 100644 --- a/examples/twisted/wamp/basic/pubsub/options/backend.py +++ b/examples/twisted/wamp/basic/pubsub/options/backend.py @@ -30,15 +30,6 @@ class Component(ApplicationSession): An application component that publishes an event every second. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): diff --git a/examples/twisted/wamp/basic/pubsub/options/frontend.py b/examples/twisted/wamp/basic/pubsub/options/frontend.py index be6ab1f3..b0c5841e 100644 --- a/examples/twisted/wamp/basic/pubsub/options/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/options/frontend.py @@ -31,10 +31,6 @@ class Component(ApplicationSession): and stop after having received 5 events. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -50,9 +46,5 @@ class Component(ApplicationSession): options = SubscribeOptions(details_arg = 'details')) - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py index e45a0208..25cc7273 100644 --- a/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.py @@ -29,15 +29,6 @@ class Component(ApplicationSession): An application component that publishes an event every second. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py index 8b637eae..703eaa48 100644 --- a/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.py @@ -53,10 +53,6 @@ class Component(ApplicationSession): print("Subscribed with subscription ID {}".format(self.subscription.id)) - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -64,9 +60,5 @@ class Component(ApplicationSession): yield self.test() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/arguments/backend.py b/examples/twisted/wamp/basic/rpc/arguments/backend.py index 9c40eef8..57c35324 100644 --- a/examples/twisted/wamp/basic/rpc/arguments/backend.py +++ b/examples/twisted/wamp/basic/rpc/arguments/backend.py @@ -28,10 +28,6 @@ class Component(ApplicationSession): An application component providing procedures with different kinds of arguments. """ - def onConnect(self): - self.join(u"realm1") - - def onJoin(self, details): def ping(): diff --git a/examples/twisted/wamp/basic/rpc/arguments/frontend.py b/examples/twisted/wamp/basic/rpc/arguments/frontend.py index 3c5bb650..1940f545 100644 --- a/examples/twisted/wamp/basic/rpc/arguments/frontend.py +++ b/examples/twisted/wamp/basic/rpc/arguments/frontend.py @@ -28,10 +28,6 @@ class Component(ApplicationSession): An application component calling the different backend procedures. """ - def onConnect(self): - self.join(u"realm1") - - @inlineCallbacks def onJoin(self, details): @@ -74,9 +70,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/complex/backend.py b/examples/twisted/wamp/basic/rpc/complex/backend.py index d78f98e3..6be6ffa1 100644 --- a/examples/twisted/wamp/basic/rpc/complex/backend.py +++ b/examples/twisted/wamp/basic/rpc/complex/backend.py @@ -30,15 +30,6 @@ class Component(ApplicationSession): return complex results. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): def add_complex(a, ai, b, bi): diff --git a/examples/twisted/wamp/basic/rpc/complex/frontend.py b/examples/twisted/wamp/basic/rpc/complex/frontend.py index 363d0e2a..d7fccd17 100644 --- a/examples/twisted/wamp/basic/rpc/complex/frontend.py +++ b/examples/twisted/wamp/basic/rpc/complex/frontend.py @@ -30,10 +30,6 @@ class Component(ApplicationSession): produce complex results and showing how to access those. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -46,9 +42,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/decorators/backend.py b/examples/twisted/wamp/basic/rpc/decorators/backend.py index 7b01055c..c3369897 100644 --- a/examples/twisted/wamp/basic/rpc/decorators/backend.py +++ b/examples/twisted/wamp/basic/rpc/decorators/backend.py @@ -30,17 +30,9 @@ class Component(ApplicationSession): An application component registering RPC endpoints using decorators. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): + print("273423") ## register all methods on this object decorated with "@wamp.procedure" ## as a RPC endpoint diff --git a/examples/twisted/wamp/basic/rpc/decorators/frontend.py b/examples/twisted/wamp/basic/rpc/decorators/frontend.py index 1e51adae..71016b48 100644 --- a/examples/twisted/wamp/basic/rpc/decorators/frontend.py +++ b/examples/twisted/wamp/basic/rpc/decorators/frontend.py @@ -28,21 +28,13 @@ class Component(ApplicationSession): An application component calling the different backend procedures. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - @inlineCallbacks def onJoin(self, details): + print("SDFJSDLF") - procs = ['com.mathservice.add2', - 'com.mathservice.mul2', - 'com.mathservice.div2'] + procs = [u'com.mathservice.add2', + u'com.mathservice.mul2', + u'com.mathservice.div2'] try: for proc in procs: @@ -54,9 +46,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/errors/backend.py b/examples/twisted/wamp/basic/rpc/errors/backend.py index 2cba6043..91df954d 100644 --- a/examples/twisted/wamp/basic/rpc/errors/backend.py +++ b/examples/twisted/wamp/basic/rpc/errors/backend.py @@ -41,15 +41,6 @@ class Component(ApplicationSession): Example WAMP application backend that raised exceptions. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): ## raising standard exceptions @@ -75,14 +66,14 @@ class Component(ApplicationSession): raise ApplicationError("com.myapp.error.mixed_case", name.lower(), name.upper()) if len(name) < 3 or len(name) > 10: - ## forward keyword arguments in exceptions + ## forward keyword arguments in exceptions raise ApplicationError("com.myapp.error.invalid_length", min = 3, max = 10) self.register(checkname, 'com.myapp.checkname') ## defining and automapping WAMP application exceptions - ## + ## self.define(AppError1) def compare(a, b): diff --git a/examples/twisted/wamp/basic/rpc/errors/frontend.py b/examples/twisted/wamp/basic/rpc/errors/frontend.py index bf6af02f..134a69e7 100644 --- a/examples/twisted/wamp/basic/rpc/errors/frontend.py +++ b/examples/twisted/wamp/basic/rpc/errors/frontend.py @@ -41,10 +41,6 @@ class Component(ApplicationSession): Example WAMP application frontend that catches exceptions. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -71,7 +67,7 @@ class Component(ApplicationSession): ## defining and automapping WAMP application exceptions - ## + ## self.define(AppError1) try: @@ -83,9 +79,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/options/backend.py b/examples/twisted/wamp/basic/rpc/options/backend.py index def49c00..c2606760 100644 --- a/examples/twisted/wamp/basic/rpc/options/backend.py +++ b/examples/twisted/wamp/basic/rpc/options/backend.py @@ -30,15 +30,6 @@ class Component(ApplicationSession): different kinds of arguments. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): def square(val, details = None): diff --git a/examples/twisted/wamp/basic/rpc/options/frontend.py b/examples/twisted/wamp/basic/rpc/options/frontend.py index 65381954..b21b5a0a 100644 --- a/examples/twisted/wamp/basic/rpc/options/frontend.py +++ b/examples/twisted/wamp/basic/rpc/options/frontend.py @@ -29,10 +29,6 @@ class Component(ApplicationSession): An application component calling the different backend procedures. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -48,9 +44,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/progress/backend.py b/examples/twisted/wamp/basic/rpc/progress/backend.py index 015a6831..a3457c89 100644 --- a/examples/twisted/wamp/basic/rpc/progress/backend.py +++ b/examples/twisted/wamp/basic/rpc/progress/backend.py @@ -30,14 +30,6 @@ class Component(ApplicationSession): Application component that produces progressive results. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - def onJoin(self, details): diff --git a/examples/twisted/wamp/basic/rpc/progress/frontend.py b/examples/twisted/wamp/basic/rpc/progress/frontend.py index e295ad95..27b2a9f0 100644 --- a/examples/twisted/wamp/basic/rpc/progress/frontend.py +++ b/examples/twisted/wamp/basic/rpc/progress/frontend.py @@ -30,10 +30,6 @@ class Component(ApplicationSession): Application component that consumes progressive results. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): @@ -47,9 +43,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/slowsquare/backend.py b/examples/twisted/wamp/basic/rpc/slowsquare/backend.py index e274f83f..cbc91770 100644 --- a/examples/twisted/wamp/basic/rpc/slowsquare/backend.py +++ b/examples/twisted/wamp/basic/rpc/slowsquare/backend.py @@ -30,15 +30,6 @@ class Component(ApplicationSession): A math service application component. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): def square(x): diff --git a/examples/twisted/wamp/basic/rpc/slowsquare/frontend.py b/examples/twisted/wamp/basic/rpc/slowsquare/frontend.py index 597acacd..485c8df0 100644 --- a/examples/twisted/wamp/basic/rpc/slowsquare/frontend.py +++ b/examples/twisted/wamp/basic/rpc/slowsquare/frontend.py @@ -19,7 +19,7 @@ import time from twisted.internet import reactor -from twisted.internet.defer import DeferredList +from twisted.internet.defer import DeferredList from autobahn.twisted.wamp import ApplicationSession @@ -30,10 +30,6 @@ class Component(ApplicationSession): An application component using the time service. """ - def onConnect(self): - self.join("realm1") - - def onJoin(self, details): def got(res, started, msg): @@ -55,9 +51,5 @@ class Component(ApplicationSession): DeferredList ([d1, d2]).addBoth(done) - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/rpc/timeservice/backend.py b/examples/twisted/wamp/basic/rpc/timeservice/backend.py index fa033dc6..b1b8043e 100644 --- a/examples/twisted/wamp/basic/rpc/timeservice/backend.py +++ b/examples/twisted/wamp/basic/rpc/timeservice/backend.py @@ -27,15 +27,6 @@ class Component(ApplicationSession): A simple time service application component. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): def utcnow(): diff --git a/examples/twisted/wamp/basic/rpc/timeservice/frontend.py b/examples/twisted/wamp/basic/rpc/timeservice/frontend.py index 0ed28b0c..d039a84b 100644 --- a/examples/twisted/wamp/basic/rpc/timeservice/frontend.py +++ b/examples/twisted/wamp/basic/rpc/timeservice/frontend.py @@ -30,10 +30,6 @@ class Component(ApplicationSession): An application component using the time service. """ - def onConnect(self): - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): try: @@ -46,9 +42,5 @@ class Component(ApplicationSession): self.leave() - def onLeave(self, details): - self.disconnect() - - def onDisconnect(self): reactor.stop() diff --git a/examples/twisted/wamp/basic/server.py b/examples/twisted/wamp/basic/server.py index c73ba76f..f8987ffd 100644 --- a/examples/twisted/wamp/basic/server.py +++ b/examples/twisted/wamp/basic/server.py @@ -35,6 +35,9 @@ if __name__ == '__main__': parser.add_argument("-c", "--component", type = str, default = None, help = "Start WAMP server with this application component, e.g. 'timeservice.TimeServiceBackend', or None.") + parser.add_argument("-r", "--realm", type = str, default = "realm1", + help = "The WAMP realm to start the component in (if any).") + parser.add_argument("--endpoint", type = str, default = "tcp:8080", help = 'Twisted server endpoint descriptor, e.g. "tcp:8080" or "unix:/tmp/mywebsocket".') @@ -84,7 +87,8 @@ if __name__ == '__main__': ## .. and create and add an WAMP application session to ## run next to the router ## - session_factory.add(SessionKlass()) + from autobahn.wamp import types + session_factory.add(SessionKlass(types.ComponentConfig(realm = args.realm))) if args.transport == "websocket": diff --git a/examples/twisted/wamp/basic/session/fromoutside/client.py b/examples/twisted/wamp/basic/session/fromoutside/client.py index e3aa3868..d8773110 100644 --- a/examples/twisted/wamp/basic/session/fromoutside/client.py +++ b/examples/twisted/wamp/basic/session/fromoutside/client.py @@ -26,13 +26,6 @@ from autobahn.twisted.wamp import ApplicationSession class MyAppComponent(ApplicationSession): - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - def onConnect(self): - self.join(self._realm) - def onJoin(self, details): if not self.factory._myAppSession: self.factory._myAppSession = self @@ -96,7 +89,7 @@ if __name__ == '__main__': ## @inlineCallbacks def pub(): - counter = 0 + counter = 0 while True: ## here we can access the app session that was created .. ## diff --git a/examples/twisted/wamp/basic/session/series/backend.py b/examples/twisted/wamp/basic/session/series/backend.py index 754abf4e..031fdcc4 100644 --- a/examples/twisted/wamp/basic/session/series/backend.py +++ b/examples/twisted/wamp/basic/session/series/backend.py @@ -30,15 +30,6 @@ class Component(ApplicationSession): A simple time service application component. """ - def __init__(self, realm = "realm1"): - ApplicationSession.__init__(self) - self._realm = realm - - - def onConnect(self): - self.join(self._realm) - - def onJoin(self, details): def utcnow(): diff --git a/examples/twisted/wamp/basic/session/series/frontend.py b/examples/twisted/wamp/basic/session/series/frontend.py index a42bd3b5..7c6a86c2 100644 --- a/examples/twisted/wamp/basic/session/series/frontend.py +++ b/examples/twisted/wamp/basic/session/series/frontend.py @@ -31,17 +31,11 @@ class Component(ApplicationSession): during 3 subsequent WAMP sessions, while the underlying transport continues to exist. """ - - def __init__(self): - ApplicationSession.__init__(self) + def __init__(self, config): + ApplicationSession.__init__(self, config) self.count = 0 - def onConnect(self): - print("Transport connected.") - self.join("realm1") - - @inlineCallbacks def onJoin(self, details): print("Realm joined (WAMP session started).")