onClose method

FutureOr<void> onClose(
  1. int code,
  2. String reason
)

Closes the connection, naming the protocol's code and reason.

The default closes the channel and loses the code, because a StreamChannel has nowhere to put it. Override this on a WebSocket transport and close the socket with code: it is how a client tells a refused connection from a malformed message from a duplicated id.

Implementation

FutureOr<void> onClose(int code, String reason) {
  client.close();
}