platformWebSocketTransport function
Creates the WebSocket transport that suits the platform the code runs
on: an IoWebSocketTransport where dart:io exists (the VM, Flutter
on mobile and desktop), a BrowserWebSocketTransport in the browser.
It lets code shared between Flutter mobile and Flutter web open
connections without conditional imports. The WebSocket starter calls
it for its default webSocketTransport bean. On a platform with
neither dart:io nor dart:js_interop it throws an
UnsupportedError: pass your own WebSocketTransport there.
maxTextMessageSize and maxBinaryMessageSize bound the messages a
session receives on dart:io (8 KB each when null, -1 for no
limit; see IoWebSocketTransport). The browser assembles messages
itself and has no such limit, so it ignores them.
final transport = platformWebSocketTransport(
maxTextMessageSize: 1024 * 1024, // the server sends large JSON
);
Spring (Java): picking a WebSocketClient implementation by hand
(StandardWebSocketClient, ReactorNettyWebSocketClient).
Implementation
WebSocketTransport platformWebSocketTransport({
int? maxTextMessageSize,
int? maxBinaryMessageSize,
}) => platform.createWebSocketTransport(
maxTextMessageSize: maxTextMessageSize,
maxBinaryMessageSize: maxBinaryMessageSize,
);