[英]How to check if the tcp socket is still connected in Flutter?
I have connected to my server as follows:我已按如下方式连接到我的服务器:
Socket socket = await Socket.connect('xxx', xxx)
But now I want to check if the socket is still connected.但现在我想检查套接字是否仍然连接。 It would be even better if I have a listener that tells me when the connection is broken.
如果我有一个监听器告诉我连接何时断开,那就更好了。
Thanks already!已经谢谢了! Leonard
伦纳德
Listen to onDone in its stream在其流中收听 onDone
socket.stream.listen(
(dynamic message) {
debugPrint('message $message');
},
onDone: () {
debugPrint('socket closed');//if closed you will get it here
},
onError: (error) {
debugPrint('error $error');
},
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.