ping 收不到pong 关闭连接
pkg\sky_engine\lib\_http\websocket.dart
/// A ping message is sent every [pingInterval], starting at the first
/// [pingInterval] after a new value has been assigned or a pong message has
/// been received. If a ping message is not answered by a pong message from the
/// peer, the `WebSocket` is assumed disconnected and the connection is closed
/// with a [WebSocketStatus.goingAway] close code. When a ping signal is sent,
/// the pong message must be received within [pingInterval].
static void connect() {
if (Global.token == '') {
dispose();
return;
}
Fluttertoast.showToast(
msg: '网络波动,连接聊天',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM);
channel = IOWebSocketChannel.connect(Config.wsUrl,
headers: headers, pingInterval: pingIntervalDuration);
channel.stream.listen(onData, onError: onError, onDone: onDone);
}
c.SetPingHandler(func(appData string) error {
chConnAlive <- struct{}{}
log.Println("SetPingHandler ", appData)
err = c.WriteMessage(websocket.PongMessage, nil)
if err != nil {
log.Println(err)
}
return err
})