sendMessage method

  1. @override
void sendMessage(
  1. Object message
)
override

Sends message as a text frame when it is a String, or as a binary frame when it is a List<int>. Throws a WebSocketException when the session is no longer open, and an ArgumentError for any other type. It does not wait for the frame to leave: the message waits in memory until the network takes it. On dart:io a session whose other side takes nothing gives up past its limits (512 KB waiting, or 10 seconds) and drops the connection, and IoWebSocketSession.flush waits until what was sent has left; see IoWebSocketSession.

Implementation

@override
void sendMessage(Object message) {
  if (!isOpen) {
    throw WebSocketException('the connection is closed', url: uri);
  }
  if (message is! String && message is! List<int>) {
    throw ArgumentError.value(message, 'message', 'a String or a List<int>');
  }
  try {
    _socket.add(message);
  } on StateError catch (error) {
    // A `WebSocket` passed to the constructor and closed directly.
    throw WebSocketException(
      'the connection is closed',
      url: uri,
      cause: error,
    );
  }
}