Closed devsheke closed 2 weeks ago
I have been having issues with consistently detecting websocket close notifications sent from the server.
If by close notification you mean the server-initiated WebSocket close (the message the server sends to the client), then you only need to monitor the close message (which you do in your code). Note that the close message sent by the server does not signal the fact that the connection is closed but only informs you that the server-initiated closing of the WebSocket connection - at this point, you typically don't drop the task on the client side. Normally you continue using the stream until the error occurs (typically ConnectionClosed
) or until the stream returns None
(which happens after the connection is closed).
Simply put, if I understood your use case correctly, you probably do not need to monitor the close message. You can just poll the stream until None
is returned or until you discover any error (Some(Err(..))
). Your current code would end up in an endless loop if the connection closes due to an unexpected error.
Hope this helps!
Hi, I have been having issues with consistently detecting websocket close notifications sent from the server. In addition to thiss, the messages are still being forwarded to the
write_stream
even though the connection has been closed. Due this issue I am not able to reliably reconnect to the websocket server. Any help regarding this issue would be highly appreciated :)Here is the source file.
relevant part of
fn read_stream
:fn connect: