dart - Dart Web套接字中是否有心跳,超时或断开连接支持?

标签 dart dart-html

在Dart中使用Web套接字时,是否有心跳,超时或断开连接支持?

最佳答案

您可以在短暂的超时后手动在客户端上重新建立与服务器的连接,如下所示:

  establishConnection() {
    connection = new WebSocket('ws://...');

    // Upon connection close, wait a while and try to re-connect.
    connection.onClose.listen((e) => new Timer(5000, (t) => establishConnection()));

    connection.onOpen.listen((_) => print('Connection to the server opened.'));
  }

我认为服务器无法做到这一点……因为浏览器是打开连接的浏览器,而Chrome和Firefox等网络浏览器不支持心跳信号。

关于dart - Dart Web套接字中是否有心跳,超时或断开连接支持?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15203850/

相关文章:

dart - 如何在 Dart 中创建单例组件,并在需要时将处理程序传递给所有其他组件?

dart - 如何在Dart应用程序中播放音频

firebase - 带有云Firestore和Firebase存储的Dart控制台应用

firebase - 如何在flutter中实现onAuthStateChanged()?

android-studio - 如何在 Android Studio 的 flutter 代码中获取函数调用的踪迹?

dart - AngularDart的角度组件的应用布局

dart - 父级分离回调中的children.clear期间的附加回调

flutter - 我该如何解决这个弱警告? "The field doesn’ t 覆盖继承的 getter 或 setter。”

forms - 如何在 Onpressed FlatButton 中放置两个条件?

html - 如何获得所选文字?