Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create():
cfg = ComponentConfig(self.realm, self.extra)
session = self.make(cfg)
return session
parser = argparse.ArgumentParser()
parser.add_argument("server_ip", type=to_unicode)
parser.add_argument("port", type=to_unicode)
parser.add_argument("realm", type=to_unicode)
parser.add_argument("key", type=to_unicode)
parser.add_argument("datapath", type=to_unicode)
args = parser.parse_args()
ai_sv = "rs://" + args.server_ip + ":" + args.port
ai_realm = args.realm
# create a Wamp session object
session = Component(ComponentConfig(ai_realm, {}))
# initialize the msgpack serializer
serializer = MsgPackSerializer()
# use Wamp-over-rawsocket
runner = ApplicationRunner(ai_sv, ai_realm, serializers=[serializer])
runner.run(session, auto_reconnect=False)
# local node management router
self._router_factory = RouterFactory(self._node_id, None, None)
self._router_session_factory = RouterSessionFactory(self._router_factory)
# start node-wide realm on node management router
rlm_config = {
'name': self._realm
}
rlm = RouterRealm(self._controller, None, rlm_config)
router = self._router_factory.start_realm(rlm)
# setup global static roles
self._add_global_roles()
# always add a realm service session
cfg = ComponentConfig(self._realm, controller=self._controller)
rlm.session = (self.ROUTER_SERVICE)(cfg, router)
self._router_session_factory.add(rlm.session,
router,
authid='serviceagent',
authrole='trusted')
self.log.info('{func} router service agent session attached [{router_service}]',
func=hltype(self.start), router_service=hltype(self.ROUTER_SERVICE))
self._router_session_factory.add(self._controller,
router,
authid='nodecontroller',
authrole='controller')
self._service_sessions[self._realm] = self._controller
self.log.info('{func} node controller session attached [{node_controller}]',
func=hltype(self.start), node_controller=hltype(self.NODE_CONTROLLER))
from autobahn.wamp import types
class MySession(ApplicationSession):
def onJoin(self, details):
print("Session attached to realm!")
log.startLogging(sys.stdout)
reactor = install_reactor()
print("Running on reactor {}".format(reactor))
session_factory = ApplicationSessionFactory(types.ComponentConfig(realm=u"realm1"))
session_factory.session = MySession
transport_factory = WampWebSocketClientFactory(session_factory, url="ws://localhost", debug=True)
client = clientFromString(reactor, "unix:/tmp/cbsocket")
client.connect(transport_factory)
reactor.run()
# create a user DB
##
userdb = UserDb()
userdb.add(authid="peter", authrole="user", ticket="magic_secret_1")
userdb.add(authid="joe", authrole="user", ticket="magic_secret_2")
# create a WAMP router session factory
##
from autobahn.twisted.wamp import RouterSessionFactory
session_factory = RouterSessionFactory(router_factory)
session_factory.session = MyRouterSession
session_factory.userdb = userdb
# start an embedded application component ..
##
component_config = types.ComponentConfig(realm="realm1")
component_session = TimeService(component_config)
session_factory.add(component_session)
# create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, args.wsurl, debug=False, debug_wamp=args.debug)
transport_factory.setProtocolOptions(failByDrop=False)
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.twisted.resource import WebSocketResource
# we serve static files under "/" ..
root = File(".")
return unicode(s, "utf-8")
parser = argparse.ArgumentParser()
parser.add_argument("server_ip", type=to_unicode)
parser.add_argument("port", type=to_unicode)
parser.add_argument("realm", type=to_unicode)
parser.add_argument("key", type=to_unicode)
parser.add_argument("datapath", type=to_unicode)
args = parser.parse_args()
ai_sv = "rs://" + args.server_ip + ":" + args.port
ai_realm = args.realm
# create a Wamp session object
session = Component(ComponentConfig(ai_realm, {}))
# initialize the msgpack serializer
serializer = MsgPackSerializer()
# use Wamp-over-rawsocket
runner = ApplicationRunner(ai_sv, ai_realm, serializers=[serializer])
runner.run(session, auto_reconnect=False)
def create():
cfg = ComponentConfig(self.realm, self.extra)
session = self.make(cfg)
session.debug_app = self.debug_app
return session
# this is to clean up stuff. it is not our business to
# possibly reconnect the underlying connection
self._countdown -= 1
if self._countdown <= 0:
try:
reactor.stop()
except ReactorNotRunning:
pass
if __name__ == '__main__':
txaio.start_logging(level='debug')
# create a WAMP session object. this is reused across multiple
# reconnects (if automatically reconnected)
session = MyAppSession(ComponentConfig(u'crossbardemo', {}))
# use WAMP-over-RawSocket
# runner = ApplicationRunner(u'rs://localhost:8080', u'crossbardemo')
# alternatively, use WAMP-over-Unix-socket
runner = ApplicationRunner(
u'ws://localhost:8080',
u'crossbardemo',
)
# alternatively, use WAMP-over-WebSocket plain (standalone, not hooked in under Twisted Web)
#runner = ApplicationRunner(u'ws://localhost:8080/ws', u'crossbardemo')
# alternatively, use WAMP-over-WebSocket running under Twisted Web (as a web resource)
# runner = ApplicationRunner(u'ws://localhost:8080/twws', u'crossbardemo')
pass
finally:
# loosing the connection to the node controller is fatal:
# stop the reactor and exit with error
if reactor.running:
reactor.addSystemEventTrigger('after', 'shutdown', os._exit, 2)
reactor.stop()
# if the reactor *isn't* running, we're already shutting down
try:
# create a WAMP application session factory
#
from autobahn.twisted.wamp import ApplicationSessionFactory
from autobahn.wamp.types import ComponentConfig
session_config = ComponentConfig(realm=options.realm, extra=options)
session_factory = ApplicationSessionFactory(session_config)
session_factory.session = WORKER_TYPE_TO_CLASS[options.type]
# create a WAMP-over-WebSocket transport server factory
#
from autobahn.twisted.websocket import WampWebSocketServerFactory
transport_factory = WampWebSocketServerFactory(session_factory, "ws://localhost", debug=False, debug_wamp=False)
transport_factory.protocol = WorkerServerProtocol
transport_factory.setProtocolOptions(failByDrop=False)
# create a protocol instance and wire up to stdio
#
from twisted.python.runtime import platform as _platform
from twisted.internet import stdio
proto = transport_factory.buildProtocol(None)
if _platform.isWindows():
counter = 0
while True:
self.publish(u'com.myapp.topic1', counter)
print("Published event.")
counter += 1
yield sleep(2)
if __name__ == '__main__':
log.startLogging(sys.stdout)
router_factory = wamp.RouterFactory()
session_factory = wamp.RouterSessionFactory(router_factory)
component_config = types.ComponentConfig(realm="realm1")
component_session = MyBackendComponent(component_config)
session_factory.add(component_session)
ws_factory = websocket.WampWebSocketServerFactory(session_factory,
debug=False,
debug_wamp=False)
ws_factory.startFactory()
ws_resource = WebSocketResource(ws_factory)
lp_resource = WampLongPollResource(session_factory, debug=True, debug_transport_id="kjmd3sBLOUnb3Fyr")
root = File(".")
root.putChild("ws", ws_resource)
root.putChild("lp", lp_resource)
web_factory = Site(root)