How to close connection gracefully after WebSocketStream.split()?
PieceOfGood opened this issue · 2 comments
For a simple situation, the close()
method needs to pass CloseFrame
:
let close_frame = CloseFrame {code: CloseCode::Normal, reason: Cow::from("")};
ws_stream.close(close_frame).await;
But if I call split() for ws_stream
to create tasks with their participation, method close()
stops taking arguments, what throws an exception on the echo server side, like this:
websockets.exceptions.ConnectionClosedError: received 1005 (no status code [internal]); then sent 1005 (no status code [internal])
The server continues to run, but in its console it is always an exception when the connection is terminated in the last way.
You can pass a Message::Close
through the Sink
part. If you look at the code of WebSocketStream::close
, that's literally what it does :)
Sink::close
comes from SinkExt
and just closes the connection directly.
Does that help?
Yes, that's what I need.
Thanks a lot!