web_socket 1.0.0 copy "web_socket: ^1.0.0" to clipboard
web_socket: ^1.0.0 copied to clipboard

Any easy-to-use library for communicating with WebSockets that has multiple implementations.

pub package package publisher

An easy-to-use library for communicating with WebSockets that has multiple implementations.

Why another WebSocket package? #

The goal of package:web_socket is to provide a simple, well-defined WebSockets interface that has consistent behavior across implementations.

package:web_socket_channel is the most popular WebSocket package but it is complex and does not have consistent behavior across implementations.

WebSocket currently has four implementations that all pass the same set of conformance tests:

Using #

import 'package:web_socket/web_socket.dart';

void main() async {
  final socket =
      await WebSocket.connect(Uri.parse('wss://ws.postman-echo.com/raw'));

  socket.events.listen((e) async {
    switch (e) {
      case TextDataReceived(text: final text):
        print('Received Text: $text');
        await socket.close();
      case BinaryDataReceived(data: final data):
        print('Received Binary: $data');
      case CloseReceived(code: final code, reason: final reason):
        print('Connection to server closed: $code [$reason]');
    }
  });

  socket.sendText('Hello Dart WebSockets! 🎉');
}
29
likes
160
points
3.29M
downloads

Publisher

verified publisherdart.dev

Weekly Downloads

Any easy-to-use library for communicating with WebSockets that has multiple implementations.

Repository (GitHub)
Contributing

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

web

More

Packages that depend on web_socket