disconnect method

void disconnect({
  1. int? code,
  2. String? reason,
})

Disconnects the socket with status code and reason for the disconnect

Implementation

void disconnect({int? code, String? reason}) {
  final conn = this.conn;
  if (conn != null) {
    connState = SocketStates.disconnected;
    if (code != null) {
      conn.sink.close(code, reason ?? '');
    } else {
      conn.sink.close();
    }
    this.conn = null;

    // remove open handles
    if (heartbeatTimer != null) heartbeatTimer?.cancel();
    reconnectTimer.reset();
  }
}