-
Notifications
You must be signed in to change notification settings - Fork 312
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
support set ping handler and pong handler #307
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just like i want to count the number of ping,or set close the connection if there is no ping message whithin two cycle. |
@nhooyr I need pings/pongs at the application layer for an app we're building a replacement for. I know work is being done on the Could this PR be merged? |
@schmidtw Sorry I won't get to this for a few weeks still. There's another change I wanted to make to let people handle close frames too. What feature are you trying to ship that relies on this? |
I have a protocol that depends on sending & receiving websocket pings and pongs. Each side of the connection expect a ping/pong within an interval & if either doesn't get the ping or pong from the other side the connection is determined to be broken & application logic notes the reason, closes down immediately & the client side will reconnect. The pings and pongs are reported as metrics as well. This is the project: https://xmidt.io/ Since this is weeks out & behind other PRs and the |
Makes sense. Yes, please fork the code for now. |
We have a similar use case where we need to send a Ping if the device hasn’t sent one within a specified time frame before closing the connection for inactivity, and this PR looks like it could address our requirements perfectly. Could you please share the current status? We’re planning to migrate from gorilla/websocket to this library, but this feature is the missing piece that’s currently blocking us from completing the migration. We truly appreciate all the effort that’s gone into this project and would prefer to avoid maintaining a fork, as it can be challenging and time-consuming to manage. Thanks again for all the great work on this library! 🙌 |
@igolaizola for status, I can share that nobody is currently working on this and this PR can't be merged as-is. We can look into getting this functionality merged, however, I see at least a few issues we'd want to address:
Questions that spring to mind are: a. Do users need to modify handlers at runtime? From discussion here and in #246, it seems like observability is the main key which answers 2 and b. I don't see a use-case for 1 and a, though, and if it indeed is a use-case, perhaps they'd need the ability to assign multiple handlers (register/deregister style). I'd be happy if people chimed in here as it'll help lock-down the feature set, cheers. Edit: I could also see the ping handler be written so that the return signature allows the library to know whether or not the ping was handled. If it wasn't handled, the library sends pong, if it was, the library assumes you did, one way or another. Also, more case(s):
|
@mafredri Thank you for your quick reply!
I believe that setting handlers during creation is sufficiently flexible. Complex logic can always be encapsulated within a custom handler, and I can't think of a use case where this wouldn’t be adequate.
In our scenario, battery-powered devices act as clients, and our cloud serves as the server. This setup requires that pings are not sent automatically because the devices are responsible for initiating them. Since we’re dealing with battery-constrained devices, optimizing resource usage is critical. Would you be open to reviewing a new PR that offers more flexible handling of Ping/Pong messages? The premise would be that these handlers are configured only during startup, and ideally the default functionality remains unchanged to avoid breaking existing implementations. |
That's an interesting use-case @igolaizola, thanks for sharing it.
Sounds great, I'm happy to review! |
first of all, thanks this good project, we are preparing a tool based on this project.
Sometimes i need do something while receive ping or pong message.
So I added this feature, is it alright