IOWebSocketChannel.connect handle errors
Posted pythonclub
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IOWebSocketChannel.connect handle errors相关的知识,希望对你有一定的参考价值。
https://github.com/dart-lang/web_socket_channel/issues/38
yes, my workaround is to create a WebSocket
directly. Something like:
final socket = await WebSocket
.connect(url.toString())
.timeout(_webSocketConnectionTimeout);
return IOWebSocketChannel(socket);
Then I wrap this in a try-catch, so I can catch SocketException
and TimeoutException
and handle these in a way that makes sense for my app.
the following way works for me:
stream = widget.webSocketChannel.stream;
streamSubscription = stream.listen(
onData,
onError: (error) {
// method calls and what not here
},
cancelOnError: true);
}
I don‘t know if it is working because I have a StreamSubscription or whether it simply is an additional step.
以上是关于IOWebSocketChannel.connect handle errors的主要内容,如果未能解决你的问题,请参考以下文章