-from ws4py.client import WebSocketBaseClient
-class WebSocketClient(WebSocketBaseClient):
-
- def __init__(self, recv_handler, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.recv_handler = recv_handler
- self.connect()
-
- def received_message(self, message):
- if message.is_text:
- message = str(message)
- self.recv_handler(message)
-
- @property
- def plom_closed(self):
- return self.client_terminated
-
-from plomrogue.io_tcp import PlomSocket
-class PlomSocketClient(PlomSocket):
-
- def __init__(self, recv_handler, url):
- import socket
- self.recv_handler = recv_handler
- host, port = url.split(':')
- super().__init__(socket.create_connection((host, port)))
-
- def close(self):
- self.socket.close()
-
- def run(self):
- import ssl
- try:
- for msg in self.recv():
- if msg == 'NEED_SSL':
- self.socket = ssl.wrap_socket(self.socket)
- continue
- self.recv_handler(msg)
- except BrokenSocketConnection:
- pass # we assume socket will be known as dead by now
-