Closed xanderdunn closed 3 years ago
Hello @xanderdunn ,
You have to repeat the whole connect->handshake->create_websocket
thing.
but it did not rescue my AsyncWebSocket from an Invalid communication state error. What is the right way to close out a connection and restart it? Is there additional state that needs to be wiped clean to get it out of a bad frame or other error state?
Since AsyncWebSocket
is associated with a connection - you can't 'rescue' it. The underlying TCP connection is dead.
One solution is to entirely replace the AsyncWebsocket with a new one, but I haven't found how to close and destruct the old one.
Yes, this is exactly what you have to do. Just delete the WebSocket object - it will automatically close the connection if that connection is not used by another object.
I see, thanks. The sockets are typically stored as std::shared_ptr<oatpp::websocket::AsyncWebSocket>
, so the idea here is to set that to nullptr
everywhere it's stored and that should be enough to destruct it? Then I can create a new socket and store it in all the relevant references.
Right
Thanks, I believe it's working as desired now.
Do you have any recommendations on the architecting of a WebSocket client connection that reconnects on error or disconnection? I believe there are several situations where this would be desirable:
onClose
/onFinishListen
handleError
. This could be anInvalid communication state
or anUnknown frame
error.I attempted to put this in my client coroutine's
handleError
:but it did not rescue my
AsyncWebSocket
from anInvalid communication state
error. What is the right way to close out a connection and restart it? Is there additional state that needs to be wiped clean to get it out of a bad frame or other error state?One solution is to entirely replace the
AsyncWebsocket
with a new one, but I haven't found how to close and destruct the old one.