karlseguin / websocket.zig

A websocket implementation for zig
MIT License
283 stars 25 forks source link

WebSocket client ping #11

Closed yarreg closed 1 year ago

yarreg commented 1 year ago

Firstly, thank you for your hard work on this library. I have been using it for a project and it's been really helpful.

I recently had a requirement where I needed to send a ping frame from the WebSocket client to check the connection status. However, I found that the Client.writeFrame method, which could be potentially used for this purpose, is not publicly accessible.

Proposal: I believe this is a feature that could be valuable for various use-cases, and I'd like to propose one of the following solutions:

karlseguin commented 1 year ago

Can you check if the last commit will work for you?

I exposed writeFrame, and also added writePing and writePong.

I also added handle_ping, handle_pong and handle_close configuration options, all defaulting to false. When true however, the corresponding message will be sent to the handle method of the handler. It'll be up to the handler to check the message.type and process it accordingly. This also disables the automatic handling of both close and ping (though in the case of close, the readLoop will still terminate).

yarreg commented 1 year ago

Thanks!