當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。