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


Python websocket.WebSocketClientFactory类代码示例

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


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

示例1: __init__

   def __init__(self, url, debug = False, ident = None):
      WebSocketClientFactory.__init__(self, url, useragent = ident, debug = debug, debugCodePaths = debug)
      self.setProtocolOptions(failByDrop = False) # spec conformance

      ## enable permessage-XXX compression extensions
      ##
      offers = [PerMessageDeflateOffer()]
      #offers = [PerMessageSnappyOffer(), PerMessageBzip2Offer(), PerMessageDeflateOffer()]
      self.setProtocolOptions(perMessageCompressionOffers = offers)

      def accept(response):
         if isinstance(response, PerMessageDeflateResponse):
            return PerMessageDeflateResponseAccept(response)

         elif isinstance(response, PerMessageBzip2Response):
            return PerMessageBzip2ResponseAccept(response)

         elif isinstance(response, PerMessageSnappyResponse):
            return PerMessageSnappyResponseAccept(response)

      self.setProtocolOptions(perMessageCompressionAccept = accept)


      self.endCaseId = None
      self.currentCaseId = 0

      self.updateReports = True
      if ident is not None:
         self.agent = ident
      else:
         self.agent = "AutobahnPython/%s" % autobahn.version
      self.resource = "/getCaseCount"
开发者ID:crossbario,项目名称:autobahn-testsuite,代码行数:32,代码来源:testee.py

示例2: run

  def run(self):
      while self.__url is None:
          discoverySocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
          discoverySocket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, True)
          discoverySocket.settimeout(5)

          discoverySocket.sendto(b"hello", ("<broadcast>", 8701))
          try:
             data, address = discoverySocket.recvfrom(1024)

             self.__url = "ws://" + address[0] + ":8702"
             print ("Found: "+ self.__url)
          except socket.timeout:
             print ("No server found")

          discoverySocket.close()

      factory = WebSocketClientFactory(self.__url, debug=False)
      #factory = WebSocketClientFactory("ws://192.168.1.7:8702", debug=False)

      factory.protocol = BotWebSocketClientProtocol

      parsed = urlparse(self.__url)

      ipaddr = parsed.netloc.replace("ws://","").split(':', 1)[0]
      print ("Connecting to: "+ipaddr+"-"+str(parsed.port))

      reactor.connectTCP(ipaddr, parsed.port, factory)
      reactor.run()
开发者ID:simotek,项目名称:tanko-bot,代码行数:29,代码来源:client.py

示例3: create_client_frame

    def create_client_frame(b64patch, **kwargs):
        """
        Kind-of hack-y; maybe better to re-factor the Protocol to have a
        frame-encoder method-call? Anyway, makes a throwaway protocol
        encode a frame for us, collects the .sendData call and returns
        the data that would have gone out. Accepts all the kwargs that
        WebSocketClientProtocol.sendFrame() accepts.
        """

        # only real way to inject a "known" secret-key for the headers
        # to line up... :/
        b64patch.return_value = b'QIatSt9QkZPyS4QQfdufO8TgkL0='

        factory = WebSocketClientFactory(protocols=['wamp.2.json'])
        factory.protocol = WebSocketClientProtocol
        factory.doStart()
        proto = factory.buildProtocol(IPv4Address('TCP', '127.0.0.9', 65534))
        proto.transport = MagicMock()
        proto.connectionMade()
        proto.data = mock_handshake_server
        proto.processHandshake()

        data = []

        def collect(d, *args):
            data.append(d)
        proto.sendData = collect

        proto.sendFrame(**kwargs)
        return b''.join(data)
开发者ID:Jnesselr,项目名称:AutobahnPython,代码行数:30,代码来源:test_websocket.py

示例4: main

def main():
    
    global command_library
    command_library = CommandLibrary()
    address = "ws://" + 'localhost'
    keyboard = Keyboard_Input()
    stdio.StandardIO(keyboard)
    multicast = reactor.listenMulticast(udpbport, 
                                        MulticastProtocol(),
                                        listenMultiple=True) 
    
    factory = WebSocketClientFactory(address + ":8084", debug = False)
    factory.setProtocolOptions(failByDrop=False)
    factory.protocol = MyClientProtocol
    #command_library.request_active_xtsm()
    try:
        connectWS(factory)
        command_library.factory = factory
        command_library.multicast = multicast
        factory.command_library = command_library
        print "........................WS Server Running......................."
    except twisted.internet.error.CannotListenError:
        print "Can't listen"
        #server_shutdown()
       
    
    global tcp
    tcp = PXI_Emulator_TCP()
        
        
    reactor.run()
开发者ID:craigprice,项目名称:XTSM_1,代码行数:31,代码来源:PXI_Emulator.py

示例5: connect

    def connect(self):
        factory = WebSocketClientFactory("ws://%s:%s/ws/" % (self.host, self.port), debug=False)
        factory.noisy = True
        factory.protocol = MdcloudWebsocketClientProtocol
        factory.protocol.client = self

        self.onc = defer.Deferred()

        key_path = os.path.expanduser('~/.mcloud/%s.key' % self.host)
        crt_path = os.path.expanduser('~/.mcloud/%s.crt' % self.host)

        class NoKeyError(Exception):
            pass

        try:
            if not self.no_ssl and self.host != '127.0.0.1':

                if not os.path.exists(key_path):
                    raise NoKeyError('Key for server "%s" not found in file "%s"' % (self.host, key_path))

                if not os.path.exists(crt_path):
                    raise NoKeyError('Key for server "%s" not found in file "%s"' % (self.host, crt_path))

                from mcloud.ssl import CtxFactory

                reactor.connectSSL(self.host, self.port, factory, CtxFactory(key_path, crt_path))
            else:
                reactor.connectTCP(self.host, self.port, factory)
        except NoKeyError:

            print 'No key found - fallback to no-ssl'
            reactor.connectTCP(self.host, self.port, factory)

        return self.onc
开发者ID:hydface2,项目名称:mcloud,代码行数:34,代码来源:remote.py

示例6: main

def main():
    log.startLogging(sys.stdout)

    factory = WebSocketClientFactory("ws://localhost:9001", debug=False)
    factory.protocol = MyClientProtocol

    reactor.connectTCP("127.0.0.1", 9001, factory)
    reactor.run()
开发者ID:sih4sing5hong5,项目名称:alex,代码行数:8,代码来源:wsrouter_client.py

示例7: main

def main():
    log.startLogging(sys.stdout)

    factory = WebSocketClientFactory("ws://localhost:9000/add", debug=False)
    factory.protocol = LeaderBoardLoadGeneratorClient

    reactor.connectTCP("127.0.0.1", 9000, factory)
    reactor.run()
开发者ID:rostykm,项目名称:redis-intro,代码行数:8,代码来源:generate_data_client.py

示例8: __init__

	def __init__(self, path, debug, debugCodePaths=False):
		WebSocketClientFactory.__init__(self, path, debug=debug, debugCodePaths=False)
	
		try:
			self.sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW)
			self.sock.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
		except:
			log.msg("Error creating raw socket", logLevel=logging.WARN)
开发者ID:marsmensch,项目名称:multitun,代码行数:8,代码来源:multitun.py

示例9: __init__

 def __init__(self, config):
     self.wsAddress      = config.get('coinbase', 'webSocket')
     self.product        = config.get('coinbase', 'product')
     factory             = WebSocketClientFactory(self.wsAddress)
     factory.protocol    = CoinbaseWebSocketClient
     factory.product     = self.product
     factory.feedHandler = None
     self.factory        = factory
开发者ID:196884,项目名称:Python,代码行数:8,代码来源:exchange_price_feed.py

示例10: _makeService

 def _makeService(self):
     """
     Construct a service for the endpoint as described.
     """
     factory = WebSocketClientFactory()
     factory.protocol = SlackProtocol
     factory.bot = self.bot
     return ClientService(self.bot, factory)
开发者ID:mithrandi,项目名称:eridanus,代码行数:8,代码来源:slack.py

示例11: __init__

 def __init__(self, url):
   WebSocketClientFactory.__init__(self, url)
   
   self.protocolInstance = None
   self.tickGap = 5
   self.tickSetup()
   
   self.connect()
开发者ID:jessertaylor,项目名称:websocket-kinect,代码行数:8,代码来源:websocket-kinect.py

示例12: gen_coinbase_source

def gen_coinbase_source():
    ret = CoinbaseSource()
    factory = WebSocketClientFactory("wss://ws-feed.exchange.coinbase.com")
    factory.queue = ret.queue
    factory.close_cb = reactor.stop
    factory.protocol = ExchangeProtocol
    connectWS(factory)
    Thread(target=reactor.run, args=(False,)).start()
    return ret
开发者ID:concord,项目名称:price-demo,代码行数:9,代码来源:CoinbaseSource.py

示例13: setup_websocket

 def setup_websocket(self):
     try:
         factory = WebSocketClientFactory("wss://ws-feed.exchange.coinbase.com")
         ClientProtocol.handler = self.handler
         factory.protocol = ClientProtocol
         connectWS(factory)
         reactor.run()
     except KeyboardInterrupt:
         factory.close()
         self.handler.close_client()
开发者ID:longtagdevelopment,项目名称:CoinPy,代码行数:10,代码来源:Coinbase.py

示例14: __init__

    def __init__(self, audioFd, summary, contentType, model, url=None, headers=None, debug=None):
        self.listeners = []
        WebSocketClientFactory.__init__(self, url=url, headers=headers, debug=debug)
        self.audioFd = audioFd
        self.summary = summary
        self.contentType = contentType
        self.model = model

        self.openHandshakeTimeout = 6
        self.closeHandshakeTimeout = 6
开发者ID:HomeHabbit,项目名称:stt-watson,代码行数:10,代码来源:WSInterfaceFactory.py

示例15: _connect_client

def _connect_client(reactor, api_auth_token, ws_url):
    factory = WebSocketClientFactory(
        url=ws_url,
        headers={
            "Authorization": "{} {}".format(SCHEME, api_auth_token),
        }
    )
    factory.protocol = _StreamingLogClientProtocol
    factory.on_open = Deferred()

    endpoint = _url_to_endpoint(reactor, ws_url)
    return endpoint.connect(factory)
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:12,代码来源:test_streaming_logs.py


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