close method

  1. @override
Future<void> close({
  1. dynamic error,
})
override

Implementation

@override
Future<void> close({error}) {
  // found at https://stackoverflow.com/questions/28745138/how-to-handle-socket-disconnects-in-dart
  if (isOpen) {
    try {
      return _socket!.drain().then((_) {
        _socket!.destroy(); // closes in and out going socket
        complete(_onDisconnect, error);
      });
    } catch (error) {
      _socket!.destroy(); // closes in and out going socket
      complete(_onDisconnect, error);
    }
  }
  return Future.value();
}