Re: [WebSocket++] Re-connecting after fail/close

1,222 views
Skip to first unread message

Peter Thorson

unread,
Jul 18, 2016, 7:54:48 AM7/18/16
to Benjamin Bizard, WebSocket++
Hi Benjamin,

Can you be more specific about what you are doing that doesn't work? Do you have a concise code example of this reconnect attempt that doesn't work?

best,

Peter


On 2016-07-08, at 08:00, Benjamin Bizard <bizard....@gmail.com> wrote:

Hello,
 
First i want to apologie if my english is not perfect, i’m french.
 
I’m using websocket++ for a school project and i’m trying to re-connect my client to a server after a connection fail or close.
I’m trying to re-connect in my fail/close handler but it seems to do nothing …
 
Do you have some example of how to do it correctly ?
 
Thank you very much.
 
Best regards,
Benjamin Bizard.

Markus Gaugusch

unread,
Jul 28, 2016, 8:47:18 AM7/28/16
to WebSocket++, bizard....@gmail.com
Hi,

I had the same problem. I'm using Boost ASIO based client and wrote a class that just tries to establish the connection until it is gone and then retry. I couldn't find an example for that. I have custom open/close handlers and no fail handler.

My class has a separate thread that retries the connection. My problem was that I did not re-init the "connection" object and tried to re-use the old one (calling connect() again for the same object). This did not work, but after creating a new object it worked. Is there any other way to reconnect without creating a new connection object? Am I leaking resources if I just re-assign the client::connection_ptr?

thanks!
Markus

Peter Thorson

unread,
Aug 10, 2016, 7:49:18 AM8/10/16
to Markus Gaugusch, WebSocket++, bizard....@gmail.com
Each connection object can be used only once. To reconnect you will need to create a new connection. If you were storing a connection_hdl or connection_ptr to the original connection it is fine to re-assign the new hdl/ptr to the old container, this will not leak. In fact not doing this will retain the old connection until you delete or reassign the last connection_ptr to it.

You can create the new connection on the same endpoint used originally and can create said connection before the old connection is dead (for example, from the close or fail handler of the previous connection).

-- 
You received this message because you are subscribed to the Google Groups "WebSocket++" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websocketpp...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages