websocket-client icon indicating copy to clipboard operation
websocket-client copied to clipboard

Handling when unable to connect

Open Jcardif opened this issue 5 years ago • 1 comments

I cannot find an event that is triggered when the client is unable to connect. In the event it is is unable to connect it keeps waiting for the connection to happen

Jcardif avatar Jun 26 '20 06:06 Jcardif

Hello @Jcardif,

subscribe to DisconnectionHappened stream. Then you can call one of:

  • Start() or await Start()
    • doesn't throw an exception
    • continuously trying to connect with delay specified by ErrorReconnectTimeout
    • performs retry until it is disposed or CancelReconnection is set to true inside DisconnectionHappened handler
    • in case of awaiting it, it will unblock execution only after successful connection
  • await StartOrFail()
    • throws an exception on connection fail
    • doesn't perform retry
    • should be awaited otherwise, you lose exception

Marfusios avatar Jun 26 '20 09:06 Marfusios