Clone this repo:
  1. b8dde80 Fix all strong-mode warnings. by Natalie Weizenbaum · 12 months ago master 0.2.1
  2. 2027ad0 Use the web_socket_channel package. by Natalie Weizenbaum · 1 year, 2 months ago 0.2.0
  3. 6d6c2c1 Update the SDK constraint. by Natalie Weizenbaum · 1 year, 3 months ago 0.1.0
  4. 7065619 Provide a WebSocketChannel. by Natalie Weizenbaum · 1 year, 3 months ago
  5. 7120b62 Get rid of all the library tags. by Natalie Weizenbaum · 1 year, 3 months ago

Web Socket Handler for Shelf

shelf_web_socket is a Shelf handler for establishing WebSocket connections. It exposes a single function, webSocketHandler, which calls an onConnection callback with a CompatibleWebSocket object for every connection that's established.

import 'package:shelf/shelf_io.dart' as shelf_io;
import 'package:shelf_web_socket/shelf_web_socket.dart';

void main() {
  var handler = webSocketHandler((webSocket) {
    webSocket.listen((message) {
      webSocket.add("echo $message");
    });
  });

  shelf_io.serve(handler, 'localhost', 8080).then((server) {
    print('Serving at ws://${server.address.host}:${server.port}');
  });
}