Skip to content

How to catch a ping to send a pong #79

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

Closed
Dixeet opened this issue Nov 13, 2015 · 2 comments
Closed

How to catch a ping to send a pong #79

Dixeet opened this issue Nov 13, 2015 · 2 comments

Comments

@Dixeet
Copy link

Dixeet commented Nov 13, 2015

Hi there,
maybe the answer of my question is obvious but i'm new with asyncio and there is something i dont understand. I'm using your module to make a websocket "proxy". So i have one coroutine "server" and one "client" which is connect to another websocket server. Unfortunately, this server close the connection after one hour without sending any event. So i want to pong when this server send a ping but i dont know how to catch this. I found https://websockets.readthedocs.org/en/latest/_modules/websockets/protocol.html#WebSocketCommonProtocol.pong but this is to send a pong. Did i miss a coroutine like websocket.pong.recv() to catch a ping request and respond with the good data ? Thanks in advance for your answer

@aaugustin
Copy link
Member

websockets automatically answers pings with pongs here: https://github.com/aaugustin/websockets/blob/master/websockets/protocol.py#L391-L393. This works regardless of whether it's running the client and the server side.

I'm not entirely sure this answers your question. If you were asking "how can I propagate a ping I receive on my server side to my client side, so than when the downstream client pings me I ping the upstream server ?" there is no good API for that. I would recommend to decouple both sides and to run an asyncio task to ping the upstream server regularly.

@Dixeet
Copy link
Author

Dixeet commented Nov 13, 2015

Hi, thanks for your answer. "I would recommend to decouple both sides and to run an asyncio task to ping the upstream server regularly" This is exactly what i did. For my client side i thought i had to handle the ping requests from the server, but you answerd me that was made automatically. Well, so i dont know why my client is disconnecting after one hour. Thanks again

@aaugustin aaugustin mentioned this issue Jun 23, 2019
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants