Skip to content
pubscout

web_socket_channel

3.0.3, released 2 years ago by tools.dart.dev

Cross‑platform WebSocket channel wrapper for Dart

WASM-readyQuiet but busy
$ flutter pub add web_socket_channel
Source repository

What it does

Provides a unified WebSocketChannel API that works on Android, iOS, web, and desktop. It wraps platform‑specific WebSocket implementations and exposes a StreamChannel interface with ready, protocol, and close details.

AI-written summary of version 3.0.3, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need a WebSocket connection that works on both mobile and web
  • You prefer a Stream‑based API over callbacks
  • You want to customize the underlying HttpClient or set a connect timeout

Skip it when

  • You only need simple HTTP requests
  • You need advanced features like automatic reconnection or message framing
  • You are building a server‑side WebSocket handler

Strengths

  • Cross‑platform support (mobile, web, desktop)
  • Stream‑based API with ready and close details
  • Customizable HttpClient and connect timeout
  • Supports WebSocket status codes via status.dart

Weaknesses

  • No built‑in reconnection logic
  • Limited to WebSocket only, no higher‑level protocols
  • Requires Dart 3.3+

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
5
import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:web_socket_channel/status.dart' as status;

void main() async {
  final wsUrl = Uri.parse('ws://example.com');
  final channel = WebSocketChannel.connect(wsUrl);
  await channel.ready;
  channel.stream.listen((message) {
    channel.sink.add('received!');
    channel.sink.close(status.goingAway);
  });
}

Alternatives

Packages that do the same job and could replace web_socket_channel.

  • http2

    An HTTP/2 implementation in Dart for low-level transport and pooled HTTP/2 requests.

  • sse_channel

    Wraps Server‑Sent Events as a StreamChannel for Dart IO and web

  • jikan_api

    Dart wrapper for the Tenrai (formerly Jikan) unofficial MyAnimeList API.

  • sync_http

    Synchronous HTTP client for Dart using RawSynchronousSockets.

Works with

Packages commonly used together with web_socket_channel: ones it builds on, ones built on it, and its own family.