-
-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keep track of latency ping/pong #1195
Comments
Yes, this is a valid request. Do you have a suggestion for what an "easy to use API" would look like from your perspective? |
thanks :) |
The simplest API possible would be |
Related to #958. |
Yes, sounds good. |
This will be available in the next release. Please find the answer to your last question here: https://websockets.readthedocs.io/en/latest/faq/misc.html#are-there-onopen-onmessage-onerror-and-onclose-callbacks |
I encountered a similar problem and I instead overrode the WebsocketProtocol class by passing the
I passed a subclass of the WebsocketProtocol as this keyword argument. My subclass kept track of additional data. In your case, you could inherit from one of the Protocol classes to react whenever you read or write a frame, or when reading or writing a PING/PONG. |
Hello,
thanks for your work ;)
I'm using websockets as a client and would like to keep an eye on latency. Your documentation says this:
https://websockets.readthedocs.io/en/stable/topics/timeouts.html?highlight=timeout#latency-issues
So clients should directly call "await websocket.ping()".
But if ping_intervall is not None, websockets is already doing pings all the time. So why doesn't it track the latency already? Then there would be no need to make additional pings to get the current latency.
I'm just an amateur programmer and I tried to overwrite the "async def ping" function to keep track of latency, but your module structure seems to be really complicated (a connect function somehow starts "WebSocketClientProtocol" but only if awaited ... this is too advanced for me to understand so I don't know how to overwrite the ping function properly)
Another reason for me to "hack" into the "def ping" is ratelimiting. Some servers only allow up to x messages per y seconds. And therefore I of course need to be aware when a ping was made, since this reduces the number of other messages I can send.
-->
I think adding optional latency tracking is a good idea in general.
And maybe you can add some kind of easy to use API to get notified about pings, so I can note them regarding ratelimiting and maybe even also await the pong message.
Of course efficiency is more important than those features, so if the tradeoff is not good, can you tell me how to overwrite the ping function properly?
The text was updated successfully, but these errors were encountered: