def binance_test_uri_length(query):
    websocket = create_connection("wss://stream.binance.com:9443/stream?streams=" + query)
    while True:
        result = websocket.recv()
        websocket.close()
        print("Received '%s'\r\n" % result)
        break
Example #2
0
 def _close_websocket(self, code=1000, reason=None):
     websocket.close(self.wfile, code, reason)
     self._websocket_connected = False
     print(
         f"Closed WebSocket connection with {self.client_address[0]}:{self.client_address[1]}"
     )
     if code != 1000:
         print(f"Code: {code} reason: {reason}")
Example #3
0
 def run():
     try:
         data = self.get_argument('data')
         logging.info('Send: %s' % data)
         websocket.send(data)
         time.sleep(0.1)
         websocket.keep_running = False
         websocket.close()
     except WebSocketConnectionClosedException:
         pass
 def testSSLopt(self):
     ssloptions = {
         "cert_reqs": ssl.CERT_NONE,
         "check_hostname": False,
         "ssl_version": ssl.PROTOCOL_TLSv1_2,
         "ciphers": "TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:\
                     TLS_AES_128_GCM_SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:\
                     ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:\
                     ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:\
                     DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:\
                     ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:\
                     ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:\
                     DHE-RSA-AES256-SHA256:ECDHE-ECDSA-AES128-SHA256:\
                     ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:\
                     ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA",
         "ecdh_curve": "prime256v1"
     }
     ws = websocket.WebSocket(sslopt=ssloptions)
     ws.connect("wss://api.bitfinex.com/ws/2")
     ws.send("Hello")
     ws.close()
Example #5
0
 def send_message(self, command, value):
     """Generic send message."""
     from websocket import _exceptions
     ws_auth = False
     for attempt in range(5):
         try:
             websocket = self._connection(
                 'wss://{host_uri}/{device_set_endpoint}'.format(
                     host_uri=self.HOST_URI,
                     device_set_endpoint=self.DEVICE_SET_ENDPOINT),
                 timeout=self.REQUEST_TIMEOUT)
             auth_mssg = json.dumps({
                 'jsonrpc': '2.0',
                 'id': 3,
                 'method': 'srvWebSocketAuth',
                 'params': {
                     'varName': self.username,
                     'apiKey': self.api_key
                 }
             })
             websocket.send(auth_mssg)
             result = websocket.recv()
         except Exception as ex:
             print("Exception during websocket authentification")
             websocket.close()
         else:
             ws_auth = True
             break
     if (ws_auth == True):
         for attempt in range(5):
             try:
                 pay_load = json.dumps({
                     'jsonrpc': '2.0',
                     'method': 'gdoModuleCommand',
                     'params': {
                         'msgType': 16,
                         'moduleType': 5,
                         'portId': 7,
                         'moduleMsg': {
                             command: value
                         },
                         'topic': self.device_id
                     }
                 })
                 websocket.send(pay_load)
                 pay_load = ""
                 result = websocket.recv()
             except Exception as ex:
                 print("Exception during sending message")
                 websocket.close()
             else:
                 break
     websocket.close()
import click_spinner
import websocket

websocket = websocket.WebSocket()
websocket.connect('ws://0.0.0.0:8000/api/stt/ws')

try:
    print('Performing speech-to-text with WebSocket...')
    with click_spinner.spinner():
        with open('audio/8455-210777-0068.wav', mode='rb') as file:
            websocket.send('{"power":1000, "paris":-1000}')
            audio = file.read()
            websocket.send_binary(audio)
            result = websocket.recv()
            print()
            print(result)
            websocket.close()
except Exception as ex:
    print(ex)
Example #7
0
 def offline(websocket):
     v = str(websocket.__hash__())
     websocket.close()
     del gWebSocketsMap[v]