当前位置: 首页>>代码示例>>Python>>正文


Python websocket.WebSocketServerFactory方法代码示例

本文整理汇总了Python中autobahn.asyncio.websocket.WebSocketServerFactory方法的典型用法代码示例。如果您正苦于以下问题:Python websocket.WebSocketServerFactory方法的具体用法?Python websocket.WebSocketServerFactory怎么用?Python websocket.WebSocketServerFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在autobahn.asyncio.websocket的用法示例。


在下文中一共展示了websocket.WebSocketServerFactory方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def __init__(self, hostname="localhost", port="8080", processor=None):
        self.hostname = hostname
        self.port = port
        self.processor = processor

        factory = WebSocketServerFactory(
            u"ws://" + hostname + u":" + str(port))

        protocol = EventProtocol
        protocol.processor = processor
        protocol.app = self

        factory.protocol = protocol

        self.loop = asyncio.get_event_loop()
        self.server = self.loop.create_server(factory, '0.0.0.0', port) 
开发者ID:Dalloriam,项目名称:engel,代码行数:18,代码来源:websocket.py

示例2: startTwisted

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def startTwisted(self):
		from twisted.python import log
		log.startLogging(open("wssserver.log", "w"))

		self.print_debug("startTwisted() started")
		ws = "ws"

		ResourceProtocol.server = self

		sslcontext = None
		if self.ssl:
			self.print_debug("using wss... and ssl")
			sslcontext = ssl.DefaultOpenSSLContextFactory(self.sslkey, self.sslcert)
			ws = "wss"

		factory = WebSocketServerFactory(u"{}://127.0.0.1:{}".format(ws, self.port))
		factory.protocol = ResourceProtocol

		listenWS(factory, sslcontext)

		reactor.run() 
开发者ID:tripzero,项目名称:python-wss,代码行数:23,代码来源:wssserver.py

示例3: __init__

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def __init__(self, singleclient=True, hostname="127.0.0.1", address="0.0.0.0", port=9000, protocol=SofiEventProtocol):
        # General application configuration info
        self.hostname = hostname
        self.address = address
        self.port = port

        # Protocol class that will manage messaging
        self.protocol = protocol
        protocol.app = self

        # Event handlers
        self.handlers = {
            'init': {'_': set()},
            'load': {'_': set()},
            'close': {'_': set()},
            'click': {'_': set()},
            'mousedown': {'_': set()},
            'mouseup': {'_': set()},
            'keydown': {'_': set()},
            'keyup': {'_': set()},
            'keypress': {'_': set()}
        }

        # Client management
        self.clients = list()
        self.singleclient = singleclient

        # Create the factory that generates protocols to handle socket communications
        factory = WebSocketServerFactory("ws://" + hostname + ":" + str(port))
        factory.protocol = protocol

        # Create the Asyncio event loop
        self.loop = asyncio.get_event_loop()

        # Create the loop server
        self.server = self.loop.create_server(factory, address, port) 
开发者ID:tryexceptpass,项目名称:sofi,代码行数:38,代码来源:app.py

示例4: test_websocket_custom_loop

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def test_websocket_custom_loop(self):

        def time_gen():
            yield
            yield

        loop = AsyncioTestLoop(time_gen)
        factory = WebSocketServerFactory(loop=loop)
        server = factory()
        transport = Mock()

        server.connection_made(transport)

    # not sure when this last worked, tests haven't been running
    # properly under asyncio for a while it seems. 
开发者ID:openstack,项目名称:deb-python-autobahn,代码行数:17,代码来源:test_asyncio_websocket.py

示例5: start

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def start(self):
		self.print_debug("start() called... debug = {}".format(self.debug))
		ws = "ws"

		sslcontext = None
		if self.ssl:
			self.print_debug("using ssl")
			try:
				sslcontext = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
				sslcontext.load_cert_chain(self.sslcert, self.sslkey)
				self.print_debug("using ssl")
			except:
				sslcontext = None
				self.print_debug("failed to use ssl")

			ws = "wss"	

		ResourceProtocol.server = self

		factory = WebSocketServerFactory(u"{0}://127.0.0.1:{1}".format(ws, self.port))
		factory.protocol = ResourceProtocol

		loop = asyncio.get_event_loop()

		coro = loop.create_server(factory, '', self.port, ssl=sslcontext)
		self.server = loop.run_until_complete(coro)

		self.print_debug("server should be started now") 
开发者ID:tripzero,项目名称:python-wss,代码行数:30,代码来源:wssserver.py

示例6: __init__

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def __init__(self, hostname=u"127.0.0.1", port=9000, processor=None):

        self.hostname = hostname
        self.port = port
        self.processor = processor

        factory = WebSocketServerFactory(u"ws://" + hostname + u":" + str(port))
        protocol = FBWEventProtocol
        protocol.processor = processor
        protocol.app = self

        factory.protocol = protocol

        self.loop = asyncio.get_event_loop()
        self.server = self.loop.create_server(factory, '0.0.0.0', port) 
开发者ID:thomasantony,项目名称:flybywire,代码行数:17,代码来源:core.py

示例7: test_async_on_connect_server

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def test_async_on_connect_server(self):
        # see also issue 757

        # for python 3.5, this can be "async def foo"
        def foo(x):
            f = txaio.create_future()
            txaio.resolve(f, x * x)
            return f

        values = []

        def on_connect(req):
            f = txaio.create_future()

            def cb(x):
                f = foo(42)
                f.add_callbacks(f, lambda v: values.append(v), None)
                return f
            txaio.add_callbacks(f, cb, None)
            return f

        factory = WebSocketServerFactory()
        server = factory()
        server.onConnect = on_connect
        transport = Mock()

        server.connection_made(transport)
        # need/want to insert real-fake handshake data?
        server.data = b"\r\n".join([
            b'GET /ws HTTP/1.1',
            b'Host: www.example.com',
            b'Sec-WebSocket-Version: 13',
            b'Origin: http://www.example.com.malicious.com',
            b'Sec-WebSocket-Extensions: permessage-deflate',
            b'Sec-WebSocket-Key: tXAxWFUqnhi86Ajj7dRY5g==',
            b'Connection: keep-alive, Upgrade',
            b'Upgrade: websocket',
            b'\r\n',  # last string doesn't get a \r\n from join()
        ])
        server.processHandshake()

        import asyncio
        from asyncio.test_utils import run_once
        run_once(asyncio.get_event_loop())

        self.assertEqual(1, len(values))
        self.assertEqual(42 * 42, values[0]) 
开发者ID:openstack,项目名称:deb-python-autobahn,代码行数:49,代码来源:test_asyncio_websocket.py

示例8: __init__

# 需要导入模块: from autobahn.asyncio import websocket [as 别名]
# 或者: from autobahn.asyncio.websocket import WebSocketServerFactory [as 别名]
def __init__(self, settings):
        coro = None
        self._started = False
        self._settings = settings
        self._spine = Spine()
        self._spine.register_event_handler("dynamicValueChanged", None)

        try:
            import asyncio
        except ImportError:
            ## Trollius >= 0.3 was renamed
            import trollius as asyncio

        from autobahn.asyncio.websocket import WebSocketServerFactory

        ssl_context = None

        if encryption.enabled():
            print("socket using ssl")
            cert_file, key_file = encryption.get_cert()
            try:
                import ssl
                ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
                ssl_context.load_cert_chain(cert_file, key_file)
                print("socket ssl found")
            except:
                ssl_context = None
                print("socket failed to use ssl")

        self._spine.log.debug(
            "start websocket on:{0}, port:{1}",
            self._settings["network"]["IPAddress"],
            self._settings["network"]["WebSocketPort"]
        )
        self.factory = WebSocketServerFactory()
        self.factory.protocol = _SpineProtocol

        self.loop = asyncio.get_event_loop()
        self.coro = self.loop.create_server(
            self.factory,
            self._settings["network"]["IPAddress"],
            self._settings["network"]["WebSocketPort"],
            ssl=ssl_context
        ) 
开发者ID:kervi,项目名称:kervi,代码行数:46,代码来源:socket_spine.py


注:本文中的autobahn.asyncio.websocket.WebSocketServerFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。