M
M
Master Ruby2021-07-14 15:41:11
Python
Master Ruby, 2021-07-14 15:41:11

How to remove the delay in receiving data when connecting via web-scoket?

Good day!

from websocket import create_connection
import orjson


config = {
    "cmd": "subscribe",
    "auth_key": "xxxxxxxxxxxxx",  
    "needed_bk": ["winline:live"],
}

request = orjson.dumps(config)

try:
    ws = create_connection("ws://echo.websocket.org/")
except ConnectionError as err:
    print(err)
else:
    ws.send(request)
    result = ws.recv()
    print(result if "cs" in result.replace("[]", "").split(",")[8] else None)
finally:
    ws.close()

The above code works, the data goes, but with a 5-7 second delay, i.e. there is no continuous flow of data. Used the same data to connect using Ruby, the data arrives without delay.
At the same time, the data is sometimes different, Ruby gives out data that Python does not give, I don’t know why. I used the module both, websocket and websockets, everything is the same.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question