disconnect method

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

Disconnects the socket with status code and reason for the disconnect

Implementation

void disconnect({Function? callback, 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;
  }
  if (callback != null) callback();
}