How to send ping to websocket server periodically

1,000 views
Skip to first unread message

Yundong Cai

unread,
Dec 21, 2021, 8:40:53 PM12/21/21
to WebSocket++
hi all, 

previously I use websocket-client at python, which has setting of ping_interval and ping_timeout to send the ping messages to websocket server periodically and check the timeout of pong from server.

For the websocket++, I did not find the similar mechanism. Should I create a thread by myself to send the ping frame/message to the server?

Do you have any recommendation? Thank you so much.

Ryan Eastwood

unread,
Mar 8, 2022, 7:14:30 AM3/8/22
to WebSocket++
I got this working nicely by creating a ping thread that would send a ping if nothing received for a period of time. The easiest way I found to do this is to create a copy of the connection handle as a member variable when the on_open function is invoked so that the ping thread can use this to find the connection. You can't pass the handle as a paramater to the thread as the handle is a weak pointer. 
Reply all
Reply to author
Forward
0 new messages