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


Python WebSocketClientFactory.protocol方法代码示例

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


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

示例1: run

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
  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,代码行数:31,代码来源:client.py

示例2: main

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
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,代码行数:33,代码来源:PXI_Emulator.py

示例3: create_client_frame

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
    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,代码行数:32,代码来源:test_websocket.py

示例4: connect

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
    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,代码行数:36,代码来源:remote.py

示例5: __init__

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
 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,代码行数:10,代码来源:exchange_price_feed.py

示例6: main

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
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,代码行数:10,代码来源:wsrouter_client.py

示例7: main

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
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,代码行数:10,代码来源:generate_data_client.py

示例8: _makeService

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
 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,代码行数:10,代码来源:slack.py

示例9: gen_coinbase_source

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
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,代码行数:11,代码来源:CoinbaseSource.py

示例10: setup_websocket

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
 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,代码行数:12,代码来源:Coinbase.py

示例11: _connect_client

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
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,代码行数:14,代码来源:test_streaming_logs.py

示例12: quote_stream

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
def quote_stream(account, venue, protocol, debug=False):
	url = 'wss://api.stockfighter.io/ob/api/ws/%(account)s/venues/%(venue)s/tickertape' % locals()

	log.startLogging(sys.stdout)
	factory = WebSocketClientFactory(url, debug=debug)
	factory.protocol = protocol

    # SSL client context: default
    ##
	if factory.isSecure:
		contextFactory = ssl.ClientContextFactory()
	else:
		contextFactory = None

	connectWS(factory, contextFactory)
	reactor.run()
开发者ID:ericlivergood,项目名称:stockfighter,代码行数:18,代码来源:api.py

示例13: onTicker

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
 def onTicker(self, data):
     """
     Called upon reception of the initial 'ticker' data, triggers WebSocket market data subscription
     """
     self.log('onTicker, data[{0}'.format(data))
     ticker = json.loads(data)
     self.log('received ticker from exchange {0}'.format(data))
     price  = ticker.get("price", None)
     if price is None:
         self.fatal("could not retrieve price")
     self.basePrice = Decimal(price)
     self.log('retrieved base price for {0}: {1}'.format(self.product, self.basePrice))
     self.log('starting websocket connection')
     factory                = WebSocketClientFactory(self.wsAddress)
     factory.protocol       = CoinbaseWebSocketClient
     factory.coinbaseClient = self
     connectWS(factory)
开发者ID:196884,项目名称:Python,代码行数:19,代码来源:coinbase_client.py

示例14: startDaemon

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
	def startDaemon(self):
		
		# build urls
		self.apiUrl = self.buildApiUrl()
		self.wsUrl = self.buildWebSocketUrl()
		
		# get token
		data = { "login" : self.setApiAuth[0], "password" : self.setApiAuth[1] }
		url = "{0}/api/auth".format(self.apiUrl)
		r = self.POST(url, data)
		
		self.serverToken = r["token"]
		
		factory = WebSocketClientFactory(self.buildWebSocketUrl() + "?token={0}".format(self.serverToken), debug=False)
		factory.protocol = SmartClientProtocol
		factory.protocol.sm = self
		reactor.connectSSL(self.baseHost, 443, factory, ssl.ClientContextFactory())
开发者ID:octoberry,项目名称:smart-support-python,代码行数:19,代码来源:sm.py

示例15: main

# 需要导入模块: from autobahn.twisted.websocket import WebSocketClientFactory [as 别名]
# 或者: from autobahn.twisted.websocket.WebSocketClientFactory import protocol [as 别名]
def main():
  parser = argparse.ArgumentParser(description="Process all withdrawals using blockchain.info wallet api")

  parser.add_argument('-b', "--blinktrade_websocket_url", action="store", dest="blintrade_webscoket_url", help='Blinktrade Websocket Url', type=str)
  parser.add_argument('-u', "--blinktrade_username", action="store", dest="blintrade_user",     help='Blinktrade User', type=str)
  parser.add_argument('-p', "--blinktrade_password", action="store", dest="blintrade_password",  help='Blinktrade Password', type=str)
  parser.add_argument('-db', "--db_engine", action="store", dest="db_engine",  help='Database Engine', type=str)
  parser.add_argument('-v', "--verbose", action="store_true", default=False, dest="verbose",  help='Verbose')

  wallet_mnemonic = getpass.getpass('wallet_mnemonic: ')

  arguments = parser.parse_args()

  if not arguments.db_engine:
    parser.print_help()
    return

  blinktrade_port = 443
  should_connect_on_ssl = True
  blinktrade_url = urlparse(arguments.blintrade_webscoket_url)
  if  blinktrade_url.port is None and blinktrade_url.scheme == 'ws':
    should_connect_on_ssl = False
    blinktrade_port = 80


  db_engine = create_engine(arguments.db_engine, echo=arguments.verbose)
  Base.metadata.create_all(db_engine)


  factory = WebSocketClientFactory(blinktrade_url.geturl())
  factory.blintrade_user = arguments.blintrade_user
  factory.blintrade_password = arguments.blintrade_password
  factory.blockchain_guid = arguments.blockchain_guid
  factory.wallet_mnemonic = wallet_mnemonic
  factory.db_session = scoped_session(sessionmaker(bind=db_engine))
  factory.verbose = arguments.verbose

  factory.protocol = BtcWithdrawalProtocol
  if should_connect_on_ssl:
    reactor.connectSSL( blinktrade_url.netloc ,  blinktrade_port , factory, ssl.ClientContextFactory() )
  else:
    reactor.connectTCP(blinktrade_url.netloc ,  blinktrade_port , factory )

  reactor.run()
开发者ID:alisheikh,项目名称:blinktrade_withdrawer,代码行数:46,代码来源:brainwallet.py


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