Dart 背景上的颤振运行websocket?
我已经写了一个基于websocket的应用程序,但是当我回到家(iOS和Android)时,websocket就不再工作了。 如何使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
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的答案表明,您不能只在后台保持套接字打开(这似乎是合理的,您将保持打开的网络连接,这可能会影响电池寿命)。根据您的用例,您可能会更好地查看推送通知或检查时间表的内容