zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    K
    士兵队列训练问题
    分析A + B Problem II
    C++中sort()的用法
    swing初级应用创建一个窗体
    java生成随机数
    JAVA数字格式化
    CodeForces
    POJ
    51Nod
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10912514.html
Copyright © 2011-2022 走看看