Clone this repo:
  1. eae2258 blast_repo fixes (#269) by Devon Carew · 13 days ago master
  2. 2630714 Bump actions/checkout from 3.5.0 to 3.5.2 (#265) by dependabot[bot] · 4 weeks ago
  3. b28bae6 Allow passing through custom http client in IO socket connect (#259) by Rexios · 8 weeks ago v2.4.0
  4. 1064b47 Fix deprecated_new_in_comment_reference (#262) by Nate Bosch · 8 weeks ago
  5. 40eb236 Bump dart-lang/setup-dart from 1.4.0 to 1.5.0 (#260) by dependabot[bot] · 9 weeks ago


The web_socket_channel package provides StreamChannel wrappers for WebSocket connections. It provides a cross-platform WebSocketChannel API, a cross-platform implementation of that API that communicates over an underlying StreamChannel, an implementation that wraps dart:io's WebSocket class, and a similar implementation that wraps dart:html's.

It also provides constants for the WebSocket protocol‘s pre-defined status codes in the status.dart library. It’s strongly recommended that users import this library with the prefix status.

import 'package:web_socket_channel/web_socket_channel.dart';
import 'package:web_socket_channel/status.dart' as status;

main() async {
  final wsUrl = Uri.parse('ws://localhost:1234')
  var channel = WebSocketChannel.connect(wsUrl); {


The WebSocketChannel class's most important role is as the interface for WebSocket stream channels across all implementations and all platforms. In addition to the base StreamChannel interface, it adds a protocol getter that returns the negotiated protocol for the socket, as well as closeCode and closeReason getters that provide information about why the socket closed.

The channel‘s sink property is also special. It returns a WebSocketSink, which is just like a StreamSink except that its close() method supports optional closeCode and closeReason parameters. These parameters allow the caller to signal to the other socket exactly why they’re closing the connection.

WebSocketChannel also works as a cross-platform implementation of the WebSocket protocol. The WebSocketChannel.connect constructor connects to a listening server using the appropriate implementation for the platform. The WebSocketChannel() constructor takes an underlying StreamChannel over which it communicates using the WebSocket protocol. It also provides the static signKey() method to make it easier to implement the initial WebSocket handshake. These are used in the shelf_web_socket package to support WebSockets in a cross-platform way.