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

Question: How to keep alive websocket sptr session without activity #2960

Open
fsmoke opened this issue Dec 6, 2024 · 1 comment
Open

Question: How to keep alive websocket sptr session without activity #2960

fsmoke opened this issue Dec 6, 2024 · 1 comment

Comments

@fsmoke
Copy link

fsmoke commented Dec 6, 2024

Hi.

I am writing notification server. Every client connects to server just to handle some notifications. So there is no any read-write work to keep sptr of my session, just rare async_write operations.

What async operation i must to do for fill the wasted time between async_writes?

May be async_ping or pong, I don't really know much about what's under the hood of websockes.

But i cannot find any explicit examples about ping-pong in beast docs.

Can anyone helps me?

@ashtum
Copy link
Collaborator

ashtum commented Dec 6, 2024

Hi,
You must always maintain an active async_read operation, as it handles ping/pong operations in the background. You just need to set proper timeout options:
websocket::stream::set_option (2 of 3 overloads)
websocket::stream_base::timeout

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