首页 > 解决方案 > Websocket 在 Flutter web 上完全断开连接

问题描述

我们有一个与推送器 websocket 的连接。我们每 40 秒发送一次 ping 消息。

正在使用的库:https ://pub.dev/packages/web_socket_channel

当发生断开连接时,我们正在登录控制台。

它考虑到onDone这里的事件

_subscription = _channel!.stream.listen(
    (e) => _handlePusherEvent(e, id),
    onDone: () => _onDone(message: 'onDone'), // Erratic clean disconnection here
    onError: (e) => _onWebsocketError(e),
);


void _onDone({required String message}) {
  print(message);
}

行为不稳定,有时会在 7 小时后完成,有时只需几分钟。我们正在记录 ping 和 pong 消息。ping 消息日志在onDone事件之前,因此它不会因为没有发送 ping 消息而被关闭。

这是推动者方面的一些问题吗?

谢谢

标签: flutterwebsocketpush-notificationflutter-webpusher

解决方案



推荐阅读