Here are the examples of the python api autobahn.twisted.websocket.WebSocketClientFactory taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
3
Source : binance_socket_manager.py
with MIT License
from Binance-docs
with MIT License
from Binance-docs
def stop_socket(self, conn_key):
if conn_key not in self._conns:
return
# disable reconnecting if we are closing
self._conns[conn_key].factory = WebSocketClientFactory(self.stream_url)
self._conns[conn_key].disconnect()
del self._conns[conn_key]
def run(self):
3
Source : preview.py
with GNU General Public License v3.0
from CPChain
with GNU General Public License v3.0
from CPChain
def run_client(self):
self.factory = WebSocketClientFactory(self.ws_url + '?action=subscribe')
self.factory.protocol = MyClientProtocol
def handler(record):
self.stream.append(record)
self.factory.handler = handler
connectWS(self.factory)
def test(self):
3
Source : test_websocket.py
with MIT License
from fbla-competitive-events
with MIT License
from fbla-competitive-events
def setUp(self):
self.factory = WebSocketClientFactory(protocols=['wamp.2.json'])
self.factory.protocol = WebSocketClientProtocol
self.factory.doStart()
self.proto = self.factory.buildProtocol(IPv4Address('TCP', '127.0.0.1', 65534))
self.transport = MagicMock()
self.proto.transport = self.transport
self.proto.connectionMade()
def tearDown(self):
3
Source : websocket.py
with MIT License
from jarret
with MIT License
from jarret
def connect(self, connect_ws_url, cb_param):
logging.info("connect")
factory = WebSocketClientFactory(connect_ws_url)
logging.info("factory: %s" % factory)
factory.protocol = OutgoingSocket
logging.info("factory 2 : %s" % factory)
factory.ms_interconnect = self
factory.ms_cb_param = cb_param
logging.info("factory 3h: %s" % factory)
logging.info("connecting")
c = connectWS(factory, timeout=10)
logging.info("connect: %s" % c)
return WebsocketConnectionAttempt(c)
def connect_tls(self, ws_url, cb_param):
3
Source : websocket.py
with MIT License
from jarret
with MIT License
from jarret
def connect_tls(self, ws_url, cb_param):
logging.info("connect: %s" % c)
factory = WebSocketClientFactory(connect_ws_url)
factory.protocol = OutgoingSocket
factory.ms_interconnect = self
factory.ms_cb_param = cb_param
contextFactory = ssl.ClientContextFactory()
c = connectWS(factory, contextFactory)
return WebsocketConnectionAttempt(c)
0
Source : websockets.py
with GNU General Public License v3.0
from ArdeshirV
with GNU General Public License v3.0
from ArdeshirV
def stop_socket(self, conn_key):
"""Stop a websocket given the connection key
:param conn_key: Socket connection key
:type conn_key: string
:returns: connection key string if successful, False otherwise
"""
if conn_key not in self._conns:
return
# disable reconnecting if we are closing
self._conns[conn_key].factory = WebSocketClientFactory(self.STREAM_URL + 'tmp_path')
self._conns[conn_key].disconnect()
del(self._conns[conn_key])
# check if we have a user stream socket
if len(conn_key) >= 60 and conn_key[:60] == self._user_listen_key:
self._stop_user_socket()
def _stop_user_socket(self):
0
Source : plugin.py
with GNU General Public License v3.0
from codelv
with GNU General Public License v3.0
from codelv
def connect(self, protocol):
d = Deferred()
factory = WebSocketClientFactory(
'ws://{}:{}'.format(self.address, self.port))
this = self
class DelegateProtocol(WebSocketClientProtocol):
""" Delegates the calls to the given protcocol """
delegate = protocol
connector = self
def onConnect(self, response):
this.connection = self
self.delegate.transport = self.transport
d.callback(self)
log.debug("ws://{}:{} connected!".format(this.address,
this.port))
self.delegate.connectionMade()
def onMessage(self, payload, isBinary):
self.delegate.dataReceived(payload)
def onClose(self, wasClean, code, reason):
log.debug("ws://{}:{} disconnected: "
"clean={} code={} reason={}!".format(
this.address, this.port, wasClean, code, reason))
self.delegate.connectionLost(reason)
factory.protocol = DelegateProtocol
self.connector = reactor.connectTCP(self.address, self.port, factory)
return d
def write(self, message):
0
Source : test_websocket.py
with MIT License
from fbla-competitive-events
with MIT License
from fbla-competitive-events
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)
# beware the evils of line-endings...
mock_handshake_client = b'GET / HTTP/1.1\r\nUser-Agent: AutobahnPython/0.10.2\r\nHost: localhost:80\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nPragma: no-cache\r\nCache-Control: no-cache\r\nSec-WebSocket-Key: 6Jid6RgXpH0RVegaNSs/4g==\r\nSec-WebSocket-Protocol: wamp.2.json\r\nSec-WebSocket-Version: 13\r\n\r\n'
0
Source : twisted_online_client.py
with Apache License 2.0
from introlab
with Apache License 2.0
from introlab
def login_callback(response):
print('login_callback', response)
if response.code == 200:
print('Login success')
body = yield readBody(response)
result = json.loads(body)
print(result)
if 'websocket_url' in result:
websocket_url = result['websocket_url']
print('Should connect to websocket URL : ', websocket_url)
# Create factory that will create an instance of our protocol
factory = WebSocketClientFactory(websocket_url)
factory.protocol = TeraDeviceWebsocketProtocol
# Read CA certificate, private key and certificate from file
with open('ca_certificate.pem') as f:
ca_cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, f.read())
with open('private_key.pem') as f:
key = OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, f.read())
with open('certificate.pem') as f:
cert = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, f.read())
# We need to attach the client and server certificates to our websocket
# factory so it can successfully connect to the remote API.
context = TeraDeviceClientContextFactory(key, cert, ca_cert)
connectWS(factory, context)
else:
print('Error login', response.code, response.phrase)
if __name__ == '__main__':
0
Source : kraken_wsclient_py.py
with MIT License
from krakenfx
with MIT License
from krakenfx
def stop_socket(self, conn_key):
"""Stop a websocket given the connection key
Parameters
----------
conn_key : str
Socket connection key
Returns
-------
str, bool
connection key string if successful, False otherwise
"""
if conn_key not in self._conns:
return
# disable reconnecting if we are closing
self._conns[conn_key].factory = WebSocketClientFactory(self.STREAM_URL)
self._conns[conn_key].disconnect()
del self._conns[conn_key]
def run(self):