IoWebSocketTransport class

The WebSocketTransport for platforms with dart:io (the Dart VM, Flutter on mobile and desktop), built on dart:io's WebSocket.

platformWebSocketTransport() returns one on these platforms, so you create it yourself only to pass an HttpClient for the handshakes: a proxy, trusted certificates. Unlike the browser transport it sends handshake headers, such as Authorization. A handshake that fails or runs out of time throws a WebSocketException.

What a session sends waits in memory while the server does not read it; past sendBufferSizeLimit bytes waiting, or when what was sent has not left within sendTimeLimit, the connection is dropped (see IoWebSocketSession). A message from the server larger than maxTextMessageSize or maxBinaryMessageSize (8 KB each by default, as Tomcat's client in Spring) is not read: the session is closed with 1009 (message too big). No extension is offered, so messages are not compressed (permessage-deflate), and a handshake answer that picks an extension, or a subprotocol that was not offered, is refused (RFC 6455 §4.1). Redirects are not followed, as in browsers.

import 'package:spring_web_dart/io.dart';

// A token in a header, which a browser could not send.
final transport = IoWebSocketTransport();
final session = await transport.connect(
  Uri.parse('wss://chat.neon.books/ws'),
  headers: HttpHeaders({'Authorization': 'Bearer $token'}),
);

Spring (Java): StandardWebSocketClient.

Implemented types

Constructors

IoWebSocketTransport({HttpClient? client, int sendBufferSizeLimit = IoWebSocketSession.defaultSendBufferSizeLimit, Duration? sendTimeLimit = IoWebSocketSession.defaultSendTimeLimit, int maxTextMessageSize = IoWebSocketSession.defaultMaxMessageSize, int maxBinaryMessageSize = IoWebSocketSession.defaultMaxMessageSize})
A transport whose handshakes go through client, an HttpClient with your proxy or TLS settings; without it a default client is used. sendBufferSizeLimit and sendTimeLimit bound what each session keeps waiting for a server that does not read; maxTextMessageSize and maxBinaryMessageSize bound each message it receives.

Properties

hashCode → int
The hash code for this object.
no setterinherited
maxBinaryMessageSize → int
The largest binary message a session receives, in bytes; as maxTextMessageSize.
final
maxTextMessageSize → int
The largest text message a session receives, in UTF-8 bytes; 8 KB by default (Tomcat's maxTextMessageBufferSize, which Spring's StandardWebSocketClient gets), -1 for no limit. A larger one is not read, and the session is closed with 1009 (message too big). Tomcat counts characters, so text outside ASCII reaches this limit sooner than Tomcat's.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sendBufferSizeLimit → int
The most bytes a session keeps waiting to be sent; 512 KB by default, -1 for no limit.
final
sendTimeLimit → Duration?
How long what a session sent may take to leave; 10 seconds by default, null for no limit.
final

Methods

connect(Uri url, {HttpHeaders? headers, List<String> protocols = const [], Duration? timeout}) → Future<WebSocketSession>
Opens a connection to url (ws: or wss:) and completes once the handshake has succeeded.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited