本文整理汇总了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"
示例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()
示例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)
示例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()
示例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
示例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()
示例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()
示例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)
示例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
示例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)
示例11: __init__
def __init__(self, url):
WebSocketClientFactory.__init__(self, url)
self.protocolInstance = None
self.tickGap = 5
self.tickSetup()
self.connect()
示例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
示例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()
示例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
示例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)