Skip to content

Latest commit

 

History

History

web_socket

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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! 🎉');
}