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


Python resource.WebSocketResource方法代码示例

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


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

示例1: hostapd_control

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def hostapd_control(self, request, chute, network):
        try:
            chute_obj = ChuteStorage.chuteList[chute]
            if not chute_access_allowed(request, chute_obj):
                return permission_denied(request)
            networkInterfaces = chute_obj.getCache('networkInterfaces')
        except KeyError:
            request.setResponseCode(404)
            return ""

        ifname = None
        for iface in networkInterfaces:
            if iface['name'] == network:
                ifname = iface['externalIntf']
                break

        ctrl_iface = os.path.join(settings.PDCONFD_WRITE_DIR, "hostapd", ifname)
        factory = hostapd_control.HostapdControlWSFactory(ctrl_iface)
        factory.setProtocolOptions(autoPingInterval=10, autoPingTimeout=5)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:22,代码来源:chute_api.py

示例2: logs

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def logs(self, request, name):
        #cors.config_cors(request)
        chute = ChuteStorage.get_chute(name)
        factory = LogSockJSFactory(chute)
        factory.setProtocolOptions(autoPingInterval=5, autoPingTimeout=2)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:8,代码来源:http_server.py

示例3: status

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def status(self, request):
        #cors.config_cors(request)
        factory = StatusSockJSFactory(self.system_status)
        factory.setProtocolOptions(autoPingInterval=5, autoPingTimeout=2)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:7,代码来源:http_server.py

示例4: chute_logs

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def chute_logs(self, request, name):
        #cors.config_cors(request)
        chute = ChuteStorage.get_chute(name)
        factory = ChuteLogWsFactory(chute)
        factory.setProtocolOptions(autoPingInterval=10, autoPingTimeout=5)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:8,代码来源:http_server.py

示例5: airshark_analyzer

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def airshark_analyzer(self, request):
        #cors.config_cors(request)
        factory = AirsharkAnalyzerFactory(self.airshark_manager)
        factory.setProtocolOptions(autoPingInterval=10, autoPingTimeout=5)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:7,代码来源:http_server.py

示例6: airshark_spectrum

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def airshark_spectrum(self, request):
        #cors.config_cors(request)
        factory = AirsharkSpectrumFactory(self.airshark_manager)
        factory.setProtocolOptions(autoPingInterval=10, autoPingTimeout=5)
        return WebSocketResource(factory) 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:7,代码来源:http_server.py

示例7: change_stream

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def change_stream(self, request, change_id):
        change = self.update_manager.find_change(change_id)
        if change is not None:
            factory = ChangeStreamFactory(change)
            factory.setProtocolOptions(autoPingInterval=10, autoPingTimeout=5)
            return WebSocketResource(factory)
        else:
            request.setResponseCode(404)
            return "{}" 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:11,代码来源:http_server.py

示例8: startService

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def startService(self):

        factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % self.port,
                                         debug=self.debug)
        factory.protocol = DispatcherProtocol
        factory.protocol.dispatcher = CommandDispatcher(self._core)

        # FIXME: Site.start/stopFactory should start/stop factories wrapped as
        # Resources
        factory.startFactory()

        resource = WebSocketResource(factory)

        # we server static files under "/" ..
        webdir = os.path.abspath(
            pkg_resources.resource_filename('leap.bitmask.core', 'web'))
        root = File(webdir)

        # and our WebSocket server under "/ws"
        root.putChild(u'bitmask', resource)

        # both under one Twisted Web Site
        site = Site(root)

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:30,代码来源:websocket.py

示例9: __init__

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def __init__(self, conf, ws_factory):
        # type: (AutopushConfig, PushServerFactory) -> None
        self.conf = conf
        self.noisy = conf.debug

        resource = DefaultResource(WebSocketResource(ws_factory))
        resource.putChild("status", StatusResource())
        Site.__init__(self, resource) 
开发者ID:mozilla-services,项目名称:autopush,代码行数:10,代码来源:websocket.py

示例10: make_web_server

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def make_web_server(server, log_requests, websocket_protocol_options=()):
    root = Root()
    wsrf = WebSocketServerFactory(None, server)
    wsrf.setProtocolOptions(**dict(websocket_protocol_options))
    root.putChild(b"v1", WebSocketResource(wsrf))

    site = PrivacyEnhancedSite(root)
    site.logRequests = log_requests

    return site 
开发者ID:warner,项目名称:magic-wormhole-mailbox-server,代码行数:12,代码来源:web.py

示例11: setUp

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def setUp(self):
    market_factory = WebSocketServerFactory('ws://localhost:8080/market_stream')
    user_factory = WebSocketServerFactory('ws://localhost:8080/user_stream')
    market_factory.protocol = MarketStreamServerProtocol
    user_factory.protocol = UserStreamServerProtocol
    market_factory.startFactory()
    user_factory.startFactory()
    root = Data('', 'text/plain')
    root.putChild(b'market_stream', WebSocketResource(market_factory))
    root.putChild(b'user_stream', WebSocketResource(user_factory))
    site = Site(root)
    reactor.listenTCP(8080, site)
    def run_server():
      reactor.run(installSignalHandlers=False)
    Thread(target=run_server).start() 
开发者ID:quedexnet,项目名称:python-api,代码行数:17,代码来源:test_api_end_to_end.py

示例12: start

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def start(self, session):
        server = self
        with enamlnative.imports():
            from twisted.internet import reactor
            from twisted.web import resource
            from twisted.web.static import File
            from twisted.web.server import Site
            from autobahn.twisted.websocket import (
                WebSocketServerFactory, WebSocketServerProtocol
            )
            from autobahn.twisted.resource import WebSocketResource

        class DevWebSocketHandler(WebSocketServerProtocol):
            def onConnect(self, request):
                print("Client connecting: {}".format(request.peer))

            def onOpen(self):
                print("WebSocket connection open.")

            def onMessage(self, payload, isBinary):
                r = session.handle_message(payload)
                self.sendMessage(json.dumps(r))

            def onClose(self, wasClean, code, reason):
                print("WebSocket connection closed: {}".format(reason))

        class MainHandler(resource.Resource):
            def render_GET(self, req):
                return server.render_editor()

            def render_POST(self, req):
                #: Allow posting events
                r = session.handle_message(req.content.getvalue())
                return json.dumps(r)

        factory = WebSocketServerFactory(
            u"ws://0.0.0.0:{}".format(session.port))
        factory.protocol = DevWebSocketHandler
        root = resource.Resource()
        root.putChild("", MainHandler())
        root.putChild("dev", WebSocketResource(factory))
        root.putChild("source", File(sys.path[0]))
        root.putChild("tmp", File(os.environ.get('TMP',sys.path[0])))
        site = Site(root)
        reactor.listenTCP(session.port, site)
        print("Twisted dev server started on {}".format(session.port)) 
开发者ID:codelv,项目名称:enaml-native,代码行数:48,代码来源:dev.py

示例13: __init__

# 需要导入模块: from autobahn.twisted import resource [as 别名]
# 或者: from autobahn.twisted.resource import WebSocketResource [as 别名]
def __init__(self, config, controller):
        super(WebApp, self).__init__()
        self.config = config
        self.controller = controller
        self.children = {}

        #-----------------------------------------------------------------------
        # Register web modules
        #-----------------------------------------------------------------------
        web_modules = config.get_options('web-modules')

        for mod_name, mod_class_name in web_modules:
            mod_class = get_object(mod_class_name)
            self.putChild(mod_name.encode('utf-8'), mod_class(self))

        #-----------------------------------------------------------------------
        # Set up the websocket
        #-----------------------------------------------------------------------
        ws_factory = WSFactory(controller=self.controller)
        ws_factory.protocol = WSProtocol
        ws_resource = WebSocketResource(ws_factory)
        self.putChild(b'ws', ws_resource)

        #-----------------------------------------------------------------------
        # Register UI modules
        #-----------------------------------------------------------------------
        assets = None
        try:
            assets = get_data(__package__, 'ui/asset-manifest.json')
            assets = assets.decode('utf-8')
        except FileNotFoundError:
            self.index = self

        if assets is not None:
            self.index = UIResource('ui/index.html')
            self.putChild(b'', self.index)

            children = [
                '/favicon.png',
                '/manifest.json',
                '/scrapy-do-logo.png'
            ]
            for child in children:
                self.register_child(child, UIResource('ui' + child))

            assets = json.loads(assets)
            for _, asset in assets['files'].items():
                if asset.startswith('/'):
                    asset = asset[1:]
                self.register_child('/' + asset, UIResource('ui/' + asset))

    #--------------------------------------------------------------------------- 
开发者ID:ljanyst,项目名称:scrapy-do,代码行数:54,代码来源:webservice.py


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