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


Python websocket.WebSocketServerFactory类代码示例

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


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

示例1: startService

    def startService(self):

        factory = WebSocketServerFactory(u"ws://127.0.0.1:%d" % self.port)
        factory.protocol = EchoServerProtocol

        # 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("echows", "web"))
        root = File(webdir)

        # and our WebSocket server under "/ws" (note that Twisted uses
        # bytes for URIs)
        root.putChild(b"ws", resource)

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

        self.site = site
        self.factory = factory

        self.listener = reactor.listenTCP(self.port, site)
开发者ID:Anggi-Permana-Harianja,项目名称:autobahn-python,代码行数:25,代码来源:echoservice.py

示例2: __init__

    def __init__(self, url):

        WebSocketServerFactory.__init__(self, url)

        self.clients = []
        self.client_state = {}
        self.tick()
开发者ID:jomido,项目名称:tswss,代码行数:7,代码来源:server.py

示例3: __init__

  def __init__(self, udp_port, nick, prefix, chatroom, url = None, protocols = [], debug = False, debugCodePaths = False):
    '''
    Args:
      udp_port (int) : The udp port to listen for WebRTC traffice.
      nick (str) : The nickname for the local user.
      prefix (str) : The prefix for the local user.
      chatroom (str) : The chatroom to join.

    Kwargs:
      url : The url for websocket server
      And other default kwargs of WebSocketServerFactory.

    A roster for the chatroom is maintained here.
    CcnxSocket created for PeetsMessages propagation if NDN.
    '''
    # super can only work with new style classes which inherits from object
    # apparently WebSocketServerFactory is old style class
    WebSocketServerFactory.__init__(self, url = url, protocols = protocols, debug = debug, debugCodePaths = debugCodePaths)
    self.handlers = {'join_room' : self.handle_join, 'send_ice_candidate' : self.handle_ice_candidate, 'send_offer' : self.handle_offer, 'media_ready' : self.handle_media_ready, 'chat_msg': self.handle_chat}
    # keep the list of local clients, first, we deal with the case where there is only one local client
    self.client = None
    # keep the list of remote users
    self.roster = None
    self.listen_port = udp_port
    self.__class__.__logger.debug('UDP-PORT=%s', str(udp_port))
    self.ccnx_socket = CcnxSocket()
    self.ccnx_socket.start()
    self.local_status_callback = lambda status: 0
    self.nick = nick
    self.prefix = prefix
    self.chatroom = chatroom
开发者ID:named-data,项目名称:peets,代码行数:31,代码来源:protocol.py

示例4: main

def main(curDir):
    class WhiteboardServerProtocol(WebSocketServerProtocol):
        def onConnect(self, connectionRequest):
            whiteboard.addClient(self)
            return None

        def onMessage(self, msg, binary):
            whiteboard.processMessage(self, msg)

    os.chdir(curDir)
    
    #log.startLogging(sys.stdout)
    debugWS = False
    debugWhiteboard = False
    whiteboard = WhiteboardServer(debugWhiteboard)

    factory = WebSocketServerFactory("ws://localhost:9000",
                                     debug = debugWS,
                                     debugCodePaths = debugWS)

    factory.protocol = WhiteboardServerProtocol
    #factory.setProtocolOptions(allowHixie76 = True)
    listenWS(factory)

    webdir = File(".")
    web = Site(webdir)
    reactor.listenTCP(8080, web)

    #threading.Thread(None, reactor.run, None).start()
    print "Starting websocket server"
    reactor.run()

    whiteboard.shutdown()
开发者ID:dpmack,项目名称:Project1536,代码行数:33,代码来源:sockServer.py

示例5: __init__

    def __init__(self, url):
        WebSocketServerFactory.__init__(self, url)
        self.clients = []
        self.tickGap = 5
        self.tickSetup()

        listenWS(self)
开发者ID:okinp,项目名称:kinect-ws-depth-vid,代码行数:7,代码来源:websocket-kinect-depth.py

示例6: __init__

 def __init__(self, protocolCls, manager, url):
     """ Initialize the Factory.
     """
     WebSocketServerFactory.__init__(self, url)
     
     self._protocolCls = protocolCls
     self._manager = manager
开发者ID:LCROBOT,项目名称:rce,代码行数:7,代码来源:protocol.py

示例7: __init__

 def __init__(self, url, debug = False, ident = None):
    if ident is not None:
       server = ident
    else:
       server = "AutobahnPython/%s" % autobahn.version
    WebSocketServerFactory.__init__(self, url, debug = debug, debugCodePaths = debug, server = server)
    self.setProtocolOptions(failByDrop = False) # spec conformance
开发者ID:MichalMazurek,项目名称:AutobahnTestSuite,代码行数:7,代码来源:testee.py

示例8: __init__

	def __init__(self, *args, **kwargs):
		# pop api parameter off
		self.api = kwargs.pop('api', None)
		self.allow_ga = kwargs.pop('allow_ga', None)
		self.deny_ga = kwargs.pop('deny_ga', None)
		
		kwargs['server'] = 'saged/0.1.0 (libcbus)'
		
		WebSocketServerFactory.__init__(self, *args, **kwargs)

		
		
		self.clients = []
		
		# wire up events so we can handle events from cdbusd and populate to clients
		
		for n, m in (
			('on_lighting_group_on', self.on_lighting_group_on),
			('on_lighting_group_off', self.on_lighting_group_off),
			('on_lighting_group_ramp', self.on_lighting_group_ramp)
		):
			api.connect_to_signal(
				handler_function=m,
				signal_name=n
			)
开发者ID:JohnTocher,项目名称:cbus,代码行数:25,代码来源:saged.py

示例9: main

def main():
    """ Main method for the websocket server """
    LOG.info('main: Start')
    udp_steward = UDPConnectionSteward()
    udp_steward.start()

    # Uncomment these two to get log from twisted
    #import sys
    #log.startLogging(sys.stdout)
    # Create context factor with key and certificate
    context_factory = ssl.DefaultOpenSSLContextFactory(
        '/home/kenni/Dokumenter/websockets/autobahn/keys/server.key',
        '/home/kenni/Dokumenter/websockets/autobahn/keys/server.crt'
    )
    # Form the webserver factory
    factory = WebSocketServerFactory("wss://localhost:9001", debug=True)
    # Set the handler
    factory.protocol = CinfWebSocketHandler
    # Listen for incoming WebSocket connections: wss://localhost:9001
    listenWS(factory, context_factory)

    try:
        reactor.run()  # pylint: disable=E1101
        time.sleep(1)
        LOG.info('main: Keyboard interrupt, websocket reactor stopped')
        udp_steward.stop()
        time.sleep(1)
        LOG.info('main: UPD Steward stopped')
    except Exception as exception_:
        LOG.exception(exception_)
        raise exception_

    LOG.info('main: Ended')
    raw_input('All stopped. Press enter to exit')
开发者ID:JNRiedel,项目名称:PyExpLabSys,代码行数:34,代码来源:websocket_server.py

示例10: __init__

   def __init__(self, spec, debug = False):

      WebSocketServerFactory.__init__(self, debug = debug, debugCodePaths = debug)
      FuzzingFactory.__init__(self, spec.get("outdir", "./reports/clients/"))

      # needed for wire log / stats
      self.logOctets = True
      self.logFrames = True

      ## WebSocket session parameters
      ##
      self.setSessionParameters(url = spec["url"],
                                protocols = spec.get("protocols", []),
                                server = "AutobahnTestSuite/%s-%s" % (autobahntestsuite.version, autobahn.version))

      ## WebSocket protocol options
      ##
      self.setProtocolOptions(**spec.get("options", {}))

      self.spec = spec

      self.CaseSet = CaseSet(CaseBasename, Cases, CaseCategories, CaseSubCategories)

      self.specCases = self.CaseSet.parseSpecCases(self.spec)
      self.specExcludeAgentCases = self.CaseSet.parseExcludeAgentCases(self.spec)
      print "Autobahn WebSockets %s/%s Fuzzing Server (Port %d%s)" % (autobahntestsuite.version, autobahn.version, self.port, ' TLS' if self.isSecure else '')
      print "Ok, will run %d test cases for any clients connecting" % len(self.specCases)
      print "Cases = %s" % str(self.specCases)
开发者ID:abrandl,项目名称:AutobahnTestSuite,代码行数:28,代码来源:fuzzing.py

示例11: serve_wss

    def serve_wss(self):
        """Start a web socket server over SSL, used by the web UI to get notifications about updates."""
        import os
        from .events import SystemEvent

        # Start a web socket server if the web UI is enabled
        if not self._config['web-ui-enabled']:
            return

        if not self._config['wss-enabled']:
            return

        if not os.path.isfile(self._config['ssl-cert']):
            self._startup_event.log_critical("Unable to activate SSL: File does not exist: %s" % self._config['ssl-cert'])
            return

        try:
            import os
            from autobahn.websocket import WebSocketServerProtocol, WebSocketServerFactory
            from twisted.internet import reactor, ssl
            from twisted.internet.error import BindError

            # Create a WebSocketClientHandler instance
            WebSocketClientHandler = WebSocketClientHandlerFactory(self._config, self._ws_clients, self._event_store, self._server_status)

            uri = u"ws://%s:%s" % (self._config['wss-host'], self._config['wss-port'])
            factory = WebSocketServerFactory(uri)
            factory.protocol = WebSocketClientHandler
            # factory.setProtocolOptions(maxConnections=2)

            # note to self: if using putChild, the child must be bytes...
            if self._config['ssl-key'] and self._config['ssl-cert']:
                contextFactory = ssl.DefaultOpenSSLContextFactory(privateKeyFileName=self._config['ssl-key'], certificateFileName=self._config['ssl-cert'])
            else:
                contextFactory = ssl.DefaultOpenSSLContextFactory(privateKeyFileName=self._config['ssl-cert'], certificateFileName=self._config['ssl-cert'])


            self._ws_server_port = reactor.listenSSL(self._config['wss-port'], factory, contextFactory)
            # self._ws_server_port = reactor.listenTCP(self._config['wss-port'], factory)

            self._server_status['wss-uri'] = "wss://%s:%s" % (self._config['wss-host'], self._config['wss-port'])

            self._startup_event.log_info("Listening for connections on %s" % self._server_status['wss-uri'])
            self._startup_event.ws_address = self._config['wss-host']
            self._startup_event.ws_port = self._config['wss-port']
            self._startup_event.set_ws_started(True)

            # Serve forever (until reactor.stop())
            reactor.run(installSignalHandlers=False)

        except BindError as e:
            self._startup_event.log_critical("Unable to start web socket server: %s" % e)

        except ImportError:
            self._startup_event.log_error("Unable to start web socket server due to missing dependency.")

        event = SystemEvent()
        self._event_store.register_action(event)
        event.log_info('WSS server did quit')
开发者ID:olipo186,项目名称:Git-Auto-Deploy,代码行数:59,代码来源:gitautodeploy.py

示例12: __init__

 def __init__(self, url, debug=False, debugCodePaths=False):
     WebSocketServerFactory.__init__(self, url, debug=debug, debugCodePaths=debugCodePaths)
     self.clients = []
     self.sensorReadings = deque([])
     self.averageReading = 0
     self.oldAverageReading = 0
     self.tickcount = 0
     self.tick()
开发者ID:junoon53,项目名称:cubepi,代码行数:8,代码来源:server.py

示例13: __init__

    def __init__(self, url, geoip_db, geoip_update_interval,
                 lang, project, *a, **kw):
        WebSocketServerFactory.__init__(self, url, *a, **kw)
        self.clients = set()
        self.tickcount = 0

        start_monitor(self, geoip_db, geoip_update_interval,
                      lang, project)  # blargh
开发者ID:hatnote,项目名称:wikimon,代码行数:8,代码来源:monitor_websocket.py

示例14: __init__

 def __init__(self, *args, **kwargs):
     self.username = kwargs.pop('username')
     self.password = kwargs.pop('password')
     self.proxy_host = kwargs.pop('proxy_host', None)
     self.proxy_port = kwargs.pop('proxy_port', 8080)
     self.clients = set()
     WebSocketServerFactory.__init__(self, *args, **kwargs)
     self.initialize()
开发者ID:cellofellow,项目名称:socialsound,代码行数:8,代码来源:socialsound.py

示例15: __init__

 def __init__(self, url, debug=False, debugCodePaths=False):
     WebSocketServerFactory.__init__(self,
                                     url,
                                     debug=debug,
                                     debugCodePaths=debugCodePaths)
     self.clients = []
     self.tickcount = 0
     start_monitor(self)
开发者ID:mahmoud,项目名称:wiki_monitor,代码行数:8,代码来源:monitor_websocket.py


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