在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/