Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 背景上的颤振运行websocket?_Dart_Flutter - Fatal编程技术网

Dart 背景上的颤振运行websocket?

Dart 背景上的颤振运行websocket?,dart,flutter,Dart,Flutter,我已经写了一个基于websocket的应用程序,但是当我回到家(iOS和Android)时,websocket就不再工作了。 如何使websocket仍在后台工作?这样服务就可以一直运行。这是我的流和订阅: channel = new IOWebSocketChannel.connect(wsUrl); globalChannel = channel; print("web socket channel connected."); // add channe

我已经写了一个基于websocket的应用程序,但是当我回到家(iOS和Android)时,websocket就不再工作了。 如何使websocket仍在后台工作?这样服务就可以一直运行。这是我的流和订阅:

channel = new IOWebSocketChannel.connect(wsUrl);
      globalChannel = channel;
      print("web socket channel connected.");

      // add channel.stream to streamController
      setState(() {
        _streamController = StreamController.broadcast();
        _streamController.addStream(channel.stream);
        globalStreamController = _streamController;
      });

      // Here we listen to ws stream and add to global messages
      // when enter chat page, globalSubscription should be stop
      // if globalSub were canceled, how to reopen it??
      globalSubscription = globalStreamController.stream.listen((data) {
}

如何让此streamcontroller在当前页面类中仍能运行而不受限制?

其他关于SO和web的答案表明,您不能只在后台保持套接字打开(这似乎是合理的,您将保持打开的网络连接,这可能会影响电池寿命)。根据您的用例,您可能会更好地查看推送通知或检查时间表的内容


看来您必须处理平台频道才能运行后台任务一般来说,您不能在iOS(无)或Android(有限)上在后台运行任意代码。