Websocket client close

Jul 15, 2015 at 12:25 PM
Edited Jul 15, 2015 at 12:30 PM
Hi all,

I have created websocket_callback_client with C++ REST SDK 2.6.0 on Windows. I had noticed the function close().wait(); spent around 5 seconds sometimes. It makes my application destroy not smooth. How do I improve closing websocket when application quit. Or it is a bug? If it didn't close() websocket when application quit, any resource or socket handle leakage it occur?

Regards,
Vince
Jul 15, 2015 at 11:01 PM
Hi Vince,

I assume you are running on Windows desktop correct, i.e. not Windows Runtime (store or phone). Yes you should be calling close on the websocket_client when you are done. The websocket_client destructor will call close automatically for you to avoid any AV/crash issues, but you shouldn't be relying on this behavior. When close is called a close frame will be sent to the server and the client will try to wait for the server to respond.

Underneath we are using Websocket++ to implement our websocket client. I took a look at the reference documentation and it states the default value for close timeout is 5000ms, which matches up perfectly with what you are seeing. It sounds like the server you are connecting to isn't responding to the close frame causing the timeout. Currently we don't expose any options with our websocket client for specifying timeout values so the defaults are being used. If you'd like to you could take a look at contributing back adding timeouts for the websocket. There are several APIs on the websocketpp::connection class for dealing with timeouts.

Steve
Jul 16, 2015 at 3:39 AM
Thanks Steve!
I'm going to investigate the source code and why no server response there is.