本文整理汇总了Python中autobahn.twisted.websocket.WampWebSocketClientFactory.setProtocolOptions方法的典型用法代码示例。如果您正苦于以下问题:Python WampWebSocketClientFactory.setProtocolOptions方法的具体用法?Python WampWebSocketClientFactory.setProtocolOptions怎么用?Python WampWebSocketClientFactory.setProtocolOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类autobahn.twisted.websocket.WampWebSocketClientFactory
的用法示例。
在下文中一共展示了WampWebSocketClientFactory.setProtocolOptions方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _create_transport_factory
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
def _create_transport_factory(reactor, transport, session_factory):
"""
Create a WAMP-over-XXX transport factory.
"""
if transport.type == u'websocket':
serializers = _create_transport_serializers(transport)
factory = WampWebSocketClientFactory(session_factory, url=transport.url, serializers=serializers)
elif transport.type == u'rawsocket':
serializer = _create_transport_serializer(transport.serializers[0])
factory = WampRawSocketClientFactory(session_factory, serializer=serializer)
else:
assert(False), 'should not arrive here'
# set the options one at a time so we can give user better feedback
for k, v in transport.options.items():
try:
factory.setProtocolOptions(**{k: v})
except (TypeError, KeyError):
# this allows us to document options as snake_case
# until everything internally is upgraded from
# camelCase
try:
factory.setProtocolOptions(
**{_camel_case_from_snake_case(k): v}
)
except (TypeError, KeyError):
raise ValueError(
"Unknown {} transport option: {}={}".format(transport.type, k, v)
)
return factory
示例2: start
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
def start(self):
"""
Starts this node. This will start a node controller
and then spawn new worker processes as needed.
The node controller will watch spawned processes,
communicate via stdio with the worker, and start
and restart the worker processes as needed.
"""
## the node controller singleton WAMP application session
##
self._node_controller_session = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory()
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._node_controller_session)
if True:
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
from twisted.internet.endpoints import serverFromString
self._router_server_transport_factory = WampWebSocketServerFactory(self._router_session_factory, "ws://localhost:9000", debug = False)
self._router_server_transport_factory.setProtocolOptions(failByDrop = False)
## start the WebSocket server from an endpoint
##
self._router_server = serverFromString(self._reactor, "tcp:9000")
self._router_server.listen(self._router_server_transport_factory)
## factory that creates router session transports. these are for clients
## that talk WAMP-WebSocket over pipes with spawned worker processes and
## for any uplink session to a management service
##
self._router_client_transport_factory = WampWebSocketClientFactory(self._router_session_factory, "ws://localhost", debug = False)
self._router_client_transport_factory.setProtocolOptions(failByDrop = False)
if False:
management_session_factory = ApplicationSessionFactory()
management_session_factory.session = NodeManagementSession
management_session_factory.node_controller_session = node_controller_session
management_transport_factory = WampWebSocketClientFactory(management_session_factory, "ws://127.0.0.1:7000")
management_transport_factory.setProtocolOptions(failByDrop = False)
management_client = clientFromString(self._reactor, "tcp:127.0.0.1:7000")
management_client.connect(management_transport_factory)
## startup the node from configuration file
##
self._node_controller_session.run_node_config(self._config)
示例3: start_remote_management_client
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
def start_remote_management_client(self):
from crossbar.management import NodeManagementSession
management_session_factory = ApplicationSessionFactory()
management_session_factory.session = NodeManagementSession
management_session_factory.node_controller_session = node_controller_session
management_transport_factory = WampWebSocketClientFactory(management_session_factory, "ws://127.0.0.1:7000")
management_transport_factory.setProtocolOptions(failByDrop = False)
management_client = clientFromString(self._reactor, "tcp:127.0.0.1:7000")
management_client.connect(management_transport_factory)
示例4: start_component
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
def start_component(self, component, router):
"""
Starts a Class or WAMPlet in this component container.
"""
if component['type'] == 'wamplet':
try:
dist = component['dist']
name = component['entry']
if self.debug:
log.msg("Worker {}: starting WAMPlet '{}/{}' in realm '{}' ..".format(self._pid, dist, name, router['realm']))
## make is supposed to make instances of ApplicationSession
make = pkg_resources.load_entry_point(dist, 'autobahn.twisted.wamplet', name)
except Exception as e:
log.msg("Worker {}: failed to import class - {}".format(e))
raise ApplicationError("crossbar.error.class_import_failed", str(e))
elif component['type'] == 'class':
try:
klassname = component['name']
if self.debug:
log.msg("Worker {}: starting class '{}' in realm '{}' ..".format(self._pid, klassname, router['realm']))
import importlib
c = klassname.split('.')
mod, kls = '.'.join(c[:-1]), c[-1]
app = importlib.import_module(mod)
## make is supposed to be of class ApplicationSession
make = getattr(app, kls)
except Exception as e:
log.msg("Worker {}: failed to import class - {}".format(e))
raise ApplicationError("crossbar.error.class_import_failed", str(e))
else:
raise ApplicationError("crossbar.error.invalid_configuration", "unknown component type '{}'".format(component['type']))
def create():
cfg = ComponentConfig(realm = router['realm'], extra = component.get('extra', None))
c = make(cfg)
return c
## create a WAMP-over-WebSocket transport client factory
##
from autobahn.twisted.websocket import WampWebSocketClientFactory
transport_factory = WampWebSocketClientFactory(create, router['url'], debug = self.debug)
transport_factory.setProtocolOptions(failByDrop = False)
## start a WebSocket client from an endpoint
##
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint, UNIXClientEndpoint
from twisted.internet.endpoints import clientFromString
from crossbar.twisted.tlsctx import TlsClientContextFactory
if False:
self._client = clientFromString(reactor, router['endpoint'])
else:
try:
endpoint_config = router.get('endpoint')
## a TCP4 endpoint
##
if endpoint_config['type'] == 'tcp':
## the host to connect ot
##
host = str(endpoint_config['host'])
## the port to connect to
##
port = int(endpoint_config['port'])
## connection timeout in seconds
##
timeout = int(endpoint_config.get('timeout', 10))
if 'tls' in endpoint_config:
ctx = TlsClientContextFactory()
## create a TLS client endpoint
##
self._client = SSL4ClientEndpoint(reactor,
host,
port,
ctx,
timeout = timeout)
else:
## create a non-TLS client endpoint
##
#.........这里部分代码省略.........
示例5: getattr
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
## dynamically load the application component ..
##
import importlib
c = args.component.split('.')
mod, klass = '.'.join(c[:-1]), c[-1]
app = importlib.import_module(mod)
## .. and set the session class on the factory
##
session_factory.session = getattr(app, klass)
## create a WAMP-over-WebSocket transport client factory
##
from autobahn.twisted.websocket import WampWebSocketClientFactory
transport_factory = WampWebSocketClientFactory(session_factory, args.wsurl, debug = args.debug)
transport_factory.setProtocolOptions(failByDrop = False)
## start a WebSocket client from an endpoint
##
client = clientFromString(reactor, args.websocket)
client.connect(transport_factory)
## now enter the Twisted reactor loop
##
reactor.run()
示例6: start
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
def start(self, transport, klassname, realm):
"""
Dynamically start an application component to run next to the router in "embedded mode".
"""
## dynamically load the application component ..
##
try:
if self.debug:
log.msg("Worker {}: starting class '{}' in realm '{}' ..".format(self._pid, klassname, realm))
import importlib
c = klassname.split('.')
mod, klass = '.'.join(c[:-1]), c[-1]
app = importlib.import_module(mod)
SessionKlass = getattr(app, klass)
except Exception as e:
if self.debug:
log.msg("Worker {}: failed to import class - {}".format(e))
raise ApplicationError("crossbar.error.class_import_failed", str(e))
else:
## create a WAMP application session factory
##
#from autobahn.twisted.wamp import ApplicationSessionFactory
#session_factory = ApplicationSessionFactory()
session_factory = ComponentSessionFactory(realm)
session_factory.session = SessionKlass
## create a WAMP-over-WebSocket transport client factory
##
from autobahn.twisted.websocket import WampWebSocketClientFactory
transport_factory = WampWebSocketClientFactory(session_factory, transport['url'], debug = self.debug)
transport_factory.setProtocolOptions(failByDrop = False)
## start a WebSocket client from an endpoint
##
from twisted.internet import reactor
from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint, UNIXClientEndpoint
from twisted.internet.endpoints import clientFromString
from tlsctx import TlsClientContextFactory
if False:
self._client = clientFromString(reactor, transport['endpoint'])
else:
try:
endpoint_config = transport.get('endpoint')
## a TCP4 endpoint
##
if endpoint_config['type'] == 'tcp':
## the host to connect ot
##
host = str(endpoint_config['host'])
## the port to connect to
##
port = int(endpoint_config['port'])
## connection timeout in seconds
##
timeout = int(endpoint_config.get('timeout', 10))
if 'tls' in endpoint_config:
ctx = TlsClientContextFactory()
## create a TLS client endpoint
##
self._client = SSL4ClientEndpoint(reactor,
host,
port,
ctx,
timeout = timeout)
else:
## create a non-TLS client endpoint
##
self._client = TCP4ClientEndpoint(reactor,
host,
port,
timeout = timeout)
## a Unix Domain Socket endpoint
##
elif endpoint_config['type'] == 'unix':
## the path
##
path = str(endpoint_config['path'])
## connection timeout in seconds
##
timeout = int(endpoint_config['type'].get('timeout', 10))
## create the endpoint
##
self._client = UNIXClientEndpoint(reactor, path, timeout = timeout)
#.........这里部分代码省略.........
示例7: __init__
# 需要导入模块: from autobahn.twisted.websocket import WampWebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WampWebSocketClientFactory import setProtocolOptions [as 别名]
class Node:
"""
A Crossbar.io node is the running a controller process
and one or multiple worker processes.
A single Crossbar.io node runs exactly one instance of
this class, hence this class can be considered a system
singleton.
"""
def __init__(self, reactor, cbdir, debug = False):
"""
Ctor.
:param reactor: Reactor to run on.
:type reactor: obj
:param cbdir: Crossbar.io node directory to run from.
:type cbdir: str
"""
self.debug = debug
self._reactor = reactor
self._cbdir = cbdir
self._worker_processes = {}
## node name: FIXME
self._node_name = "{}-{}".format(socket.getfqdn(), os.getpid())
self._node_name.replace('-', '_')
self._node_name = '918234'
## node management
self._management_url = "ws://127.0.0.1:7000"
#self._management_url = "wss://cloud.crossbar.io"
self._management_realm = "crossbar.cloud.aliceblue"
## load Crossbar.io node configuration
##
cf = os.path.join(self._cbdir, 'config.json')
with open(cf, 'rb') as infile:
self._config = json.load(infile)
def start(self):
"""
Starts this node. This will start a node controller
and then spawn new worker processes as needed.
The node controller will watch spawned processes,
communicate via stdio with the worker, and start
and restart the worker processes as needed.
"""
## the node controller singleton WAMP application session
##
self._node_controller_session = NodeControllerSession(self)
## router and factory that creates router sessions
##
self._router_factory = RouterFactory()
self._router_session_factory = RouterSessionFactory(self._router_factory)
## add the node controller singleton session to the router
##
self._router_session_factory.add(self._node_controller_session)
if True:
## create a WAMP-over-WebSocket transport server factory
##
from autobahn.twisted.websocket import WampWebSocketServerFactory
from twisted.internet.endpoints import serverFromString
self._router_server_transport_factory = WampWebSocketServerFactory(self._router_session_factory, "ws://localhost:9000", debug = False)
self._router_server_transport_factory.setProtocolOptions(failByDrop = False)
## start the WebSocket server from an endpoint
##
self._router_server = serverFromString(self._reactor, "tcp:9000")
self._router_server.listen(self._router_server_transport_factory)
## factory that creates router session transports. these are for clients
## that talk WAMP-WebSocket over pipes with spawned worker processes and
## for any uplink session to a management service
##
self._router_client_transport_factory = WampWebSocketClientFactory(self._router_session_factory, "ws://localhost", debug = False)
self._router_client_transport_factory.setProtocolOptions(failByDrop = False)
if False:
management_session_factory = ApplicationSessionFactory()
management_session_factory.session = NodeManagementSession
management_session_factory.node_controller_session = node_controller_session
management_transport_factory = WampWebSocketClientFactory(management_session_factory, "ws://127.0.0.1:7000")
management_transport_factory.setProtocolOptions(failByDrop = False)
management_client = clientFromString(self._reactor, "tcp:127.0.0.1:7000")
management_client.connect(management_transport_factory)
## startup the node from configuration file
##
self._node_controller_session.run_node_config(self._config)