码迷,mamicode.com
首页 > Web开发 > 详细

IOWebSocketChannel.connect handle errors

时间:2019-05-23 16:54:57      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:return   directly   soc   this   play   art   await   eth   rip   

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

标签:return   directly   soc   this   play   art   await   eth   rip   

原文地址:https://www.cnblogs.com/pythonClub/p/10912514.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!