dart-lang / dart-lang/http

How to reconnect and resend request?

Open
#1,567 2 comments 9 reactions 0 assignees View on GitHub
package:web_socket_channel
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

My code below,but I caught a ANR ,I want know the correct method to reconnect, thx.
```
_listen() async {
_channel.stream.listen((message) {

}, onError: (error) async {
Fluttertoast.showToast(msg: "onerror");
await Future.delayed(Duration(milliseconds: 1000));
reConnect();
}, onDone: () async {
Fluttertoast.showToast(msg: "ondone");
await Future.delayed(Duration(milliseconds: 1000));
reConnect();
});
}

void reConnect() {
print("reConnect------>IOWebSocketChannel");
_channel = IOWebSocketChannel.connect(Address.SOCKET_BASE_URL_RELEASE);
_channel.sink.add(getHistoryDealParam());
_channel.sink.add(getRealTimeDeal());
_listen();
}

```
@dart-lang

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.