Skip to content
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

How to measure ping from websocket gateway #60

Closed
Slexyy opened this issue May 4, 2021 · 0 comments
Closed

How to measure ping from websocket gateway #60

Slexyy opened this issue May 4, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@Slexyy
Copy link

Slexyy commented May 4, 2021

Hello!

I tried to look from the documentation but didn't find any ways to measure the ping to the websocket gateway, any ideas how to measure the latency between receiving the message from the websocket?

The discord.js library has a function named client.ws.ping which, referring to the docs, prints the number that is your latency to the gateway. Don't know how that is implemented.


arandomnewaccount:
well, according to discord.py (https://github.com/Rapptz/discord.py/blob/master/discord/shard.py#L261), latency = seconds between a HEARTBEAT and a HEARTBEAT_ACK.
HEARTBEAT is something your client sends (https://github.com/Merubokkusu/Discord-S.C.U.M/blob/master/discum/gateway/gateway.py#L220) and HEARTBEAT_ACK is what discord responds with (opcode 11).
So...it's currently not implemented in discum but when I get some time I can.

edit: added latency calculations in the last commit push. You can access the gateway latency by doing bot.gateway.latency. Also you'll have to wait ~30 seconds on the first gateway connection since that's about how much time discum waits until sending a heartbeat.
Close code handling was also added; make sure you update your websocket-client installation since they updated their lib to send close codes :).

edit: closing this as answered. You can access gateway latency by doing bot.gateway.latency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants
@Slexyy and others